-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
35 changed files
with
366 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,3 +7,11 @@ | |
/pkg/ | ||
/spec/reports/ | ||
/tmp/ | ||
# C9 | ||
.c9 | ||
# RubyMine | ||
.idea | ||
# Env | ||
.env | ||
# VCR | ||
/spec/cassettes |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
fub_client |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
ruby-2.3.1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,9 +9,9 @@ Gem::Specification.new do |spec| | |
spec.authors = ["Kyoto Kopz"] | ||
spec.email = ["[email protected]"] | ||
|
||
spec.summary = %q{TODO: Write a short summary, because Rubygems requires one.} | ||
spec.description = %q{TODO: Write a longer description or delete this line.} | ||
spec.homepage = "TODO: Put your gem's website or public repo URL here." | ||
spec.summary = 'Ruby client for Follow Up Boss API http://www.followupboss.com' | ||
# spec.description = %q{TODO: Write a longer description or delete this line.} | ||
spec.homepage = "https://github.com/kopz9999/fub_client" | ||
spec.license = "MIT" | ||
|
||
# Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host' | ||
|
@@ -27,7 +27,16 @@ Gem::Specification.new do |spec| | |
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) } | ||
spec.require_paths = ["lib"] | ||
|
||
spec.add_dependency "her", "~> 0.8.1" | ||
spec.add_dependency "faraday", "~> 0.8.11" | ||
spec.add_dependency "facets", "~> 3.0.0" | ||
|
||
# Developemnt | ||
spec.add_development_dependency "bundler", "~> 1.12" | ||
spec.add_development_dependency "rake", "~> 10.0" | ||
spec.add_development_dependency "rspec", "~> 3.0" | ||
spec.add_development_dependency "dotenv", "~> 2.1.1" | ||
spec.add_development_dependency "vcr", "~> 3.0.3" | ||
spec.add_development_dependency "webmock", "~> 2.1.0" | ||
spec.add_development_dependency "pry", "~> 0.10.3" | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,29 @@ | ||
# Libs | ||
require 'base64' | ||
require 'singleton' | ||
require 'faraday' | ||
require 'her' | ||
require 'facets/string/snakecase' | ||
|
||
# App | ||
require "fub_client/version" | ||
require "fub_client/client" | ||
require "fub_client/middleware" | ||
require "fub_client/resource" | ||
# App Models | ||
require "fub_client/event" | ||
require "fub_client/person" | ||
require "fub_client/note" | ||
require "fub_client/call" | ||
require "fub_client/user" | ||
require "fub_client/smart_list" | ||
require "fub_client/email_template" | ||
require "fub_client/action_plan" | ||
require "fub_client/em_event" | ||
require "fub_client/custom_field" | ||
|
||
module FubClient | ||
# Your code goes here... | ||
def self.root | ||
File.expand_path '../..', __FILE__ | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
module FubClient | ||
class ActionPlan < Resource | ||
collection_path 'actionPlans' | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
module FubClient | ||
class Call < Resource | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
module FubClient | ||
class Client | ||
API_URL = 'api.followupboss.com' | ||
API_VERSION = 'v1' | ||
|
||
include Singleton | ||
|
||
attr_writer :api_key | ||
attr_reader :her_api | ||
|
||
def initialize | ||
init_her_api | ||
end | ||
|
||
def api_key | ||
@api_key ||= ENV['FUB_API_KEY'] | ||
end | ||
|
||
def api_uri | ||
@api_uri ||= URI::HTTPS.build(host: API_URL, path: "/#{API_VERSION}") | ||
end | ||
|
||
private | ||
|
||
def init_her_api | ||
@her_api = Her::API.new | ||
@her_api.setup url: self.api_uri.to_s do |c| | ||
# Request | ||
c.use FubClient::Middleware::Authentication | ||
c.use Faraday::Request::UrlEncoded | ||
|
||
# Response | ||
c.use FubClient::Middleware::Parser | ||
|
||
# Adapter | ||
c.use Faraday::Adapter::NetHttp | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
module FubClient | ||
class CustomField < Resource | ||
collection_path 'customFields' | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
module FubClient | ||
class EmEvent < Resource | ||
collection_path 'emEvents' | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
module FubClient | ||
class EmailTemplate < Resource | ||
collection_path 'templates' | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
module FubClient | ||
class Event < Resource | ||
attributes :created, :updated, :person_id, :message, :description, | ||
:note_id, :source, :type, :property | ||
|
||
belongs_to :person | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
require "fub_client/middleware/authentication" | ||
require "fub_client/middleware/parser" | ||
|
||
module FubClient | ||
module Middleware | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
module FubClient | ||
module Middleware | ||
class Authentication < Faraday::Middleware | ||
def call(env) | ||
env[:request_headers]["Authorization"] = "Basic " + | ||
Base64.strict_encode64("#{FubClient::Client.instance.api_key}:") | ||
@app.call(env) | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
module FubClient | ||
module Middleware | ||
class Parser < Faraday::Response::Middleware | ||
|
||
def on_complete(env) | ||
original_json = MultiJson.load(env[:body]) | ||
json = original_json.deep_transform_keys{ |k| k.to_s.snakecase.to_sym } | ||
metadata = json[:_metadata] | ||
if metadata.nil? | ||
result = json | ||
else | ||
result = json[metadata[:collection].snakecase.to_sym] | ||
end | ||
env[:body] = { | ||
data: result, | ||
errors: json[:errors], | ||
metadata: metadata | ||
} | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
module FubClient | ||
class Note < Resource | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
module FubClient | ||
class Person < Resource | ||
collection_path 'people' | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
module FubClient | ||
class Resource | ||
include Her::Model | ||
use_api FubClient::Client.instance.her_api | ||
|
||
scope :by_page, -> (page, per_page) { | ||
where(offset: (page - 1)*per_page, limit: per_page) | ||
} | ||
|
||
def self.total | ||
by_page(1, 1).metadata[:total] | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
module FubClient | ||
class SmartList < Resource | ||
collection_path 'smartLists' | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
module FubClient | ||
class User < Resource | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
require 'spec_helper' | ||
|
||
describe FubClient::ActionPlan, :vcr do | ||
describe '.all' do | ||
it 'pulls down resource' do | ||
objects = described_class.all | ||
expect(objects.length).to be > 0 | ||
expect(objects.first).to be_kind_of(described_class) | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
require 'spec_helper' | ||
|
||
describe FubClient::Call, :vcr do | ||
describe '.all' do | ||
it 'pulls down resource' do | ||
objects = described_class.all | ||
expect(objects.length).to be > 0 | ||
expect(objects.first).to be_kind_of(described_class) | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
require 'spec_helper' | ||
|
||
describe FubClient::CustomField, :vcr do | ||
describe '.all' do | ||
it 'pulls down resource' do | ||
objects = described_class.all | ||
expect(objects.length).to be > 0 | ||
expect(objects.first).to be_kind_of(described_class) | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
require 'spec_helper' | ||
|
||
describe FubClient::EmEvent, :vcr do | ||
describe '.all' do | ||
it 'pulls down resource' do | ||
objects = described_class.all | ||
expect(objects.length).to be > 0 | ||
expect(objects.first).to be_kind_of(described_class) | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
require 'spec_helper' | ||
|
||
describe FubClient::EmailTemplate, :vcr do | ||
describe '.all' do | ||
it 'brings the correct event' do | ||
objects = described_class.all | ||
expect(objects.length).to be > 0 | ||
expect(objects.first).to be_kind_of(described_class) | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
require 'spec_helper' | ||
|
||
describe FubClient::Event, :vcr do | ||
describe '.find' do | ||
it 'brings the correct event' do | ||
evt = described_class.find 11195 | ||
expect(evt).not_to be_nil | ||
expect(evt).to have_attributes(person_id: 24477, message: '', | ||
description: "Best Time to Call: Today; Email: "+ | ||
"[email protected]; Phone Number: 407-705-3915", note_id: nil, | ||
source: 'Curaytor Appointment', type: 'Registration') | ||
end | ||
end | ||
|
||
describe '.all' do | ||
it 'brings the correct event' do | ||
events = described_class.all | ||
expect(events.length).to be > 0 | ||
expect(events.first).to be_kind_of(described_class) | ||
end | ||
end | ||
|
||
describe '.by_page' do | ||
it 'brings the correct person' do | ||
events = described_class.by_page(3, 25) | ||
expect(events.metadata[:offset]).to eq 50 | ||
expect(events.metadata[:limit]).to eq 25 | ||
end | ||
end | ||
|
||
describe '.total' do | ||
it 'gets the number of records' do | ||
expect(described_class.total).to eq 11105 | ||
end | ||
end | ||
|
||
describe '#person' do | ||
it 'brings the correct person' do | ||
evt = described_class.find 11195 | ||
expect(evt).not_to be_nil | ||
expect(evt.person).not_to be_nil | ||
expect(evt.person).to be_kind_of(FubClient::Person) | ||
expect(evt.person).to have_attributes(name: 'Dan Lopez', | ||
source_url: "http://curaytor.com/schedule") | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
require 'spec_helper' | ||
|
||
describe FubClient::Note, :vcr do | ||
describe '.all' do | ||
it 'pulls down resource' do | ||
objects = described_class.all | ||
expect(objects.length).to be > 0 | ||
expect(objects.first).to be_kind_of(described_class) | ||
end | ||
end | ||
end |
Oops, something went wrong.