closeio 1.0.7 → 2.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (47) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +7 -0
  3. data/Gemfile +0 -1
  4. data/Gemfile.lock +21 -10
  5. data/README.md +20 -17
  6. data/closeio.gemspec +10 -6
  7. data/lib/closeio.rb +1 -42
  8. data/lib/closeio/client.rb +59 -0
  9. data/lib/closeio/resources/activity.rb +81 -0
  10. data/lib/closeio/resources/bulk_action.rb +34 -0
  11. data/lib/closeio/resources/contact.rb +37 -0
  12. data/lib/closeio/resources/custom_field.rb +33 -0
  13. data/lib/closeio/resources/email_template.rb +32 -0
  14. data/lib/closeio/resources/lead.rb +40 -0
  15. data/lib/closeio/resources/lead_status.rb +29 -0
  16. data/lib/closeio/resources/opportunity.rb +37 -0
  17. data/lib/closeio/resources/opportunity_status.rb +29 -0
  18. data/lib/closeio/resources/organization.rb +15 -0
  19. data/lib/closeio/resources/paginated_list.rb +4 -0
  20. data/lib/closeio/resources/report.rb +19 -0
  21. data/lib/closeio/resources/smart_view.rb +33 -0
  22. data/lib/closeio/resources/task.rb +37 -0
  23. data/lib/closeio/resources/user.rb +15 -0
  24. data/lib/closeio/version.rb +1 -1
  25. metadata +86 -35
  26. data/.document +0 -5
  27. data/lib/closeio/activity_report.rb +0 -20
  28. data/lib/closeio/base.rb +0 -92
  29. data/lib/closeio/bulk_action.rb +0 -25
  30. data/lib/closeio/config.rb +0 -23
  31. data/lib/closeio/contact.rb +0 -3
  32. data/lib/closeio/custom_field.rb +0 -8
  33. data/lib/closeio/custom_report.rb +0 -15
  34. data/lib/closeio/email_activity.rb +0 -8
  35. data/lib/closeio/email_template.rb +0 -3
  36. data/lib/closeio/lead.rb +0 -28
  37. data/lib/closeio/lead_status.rb +0 -7
  38. data/lib/closeio/note_activity.rb +0 -8
  39. data/lib/closeio/opportunity.rb +0 -15
  40. data/lib/closeio/opportunity_status.rb +0 -7
  41. data/lib/closeio/organization.rb +0 -8
  42. data/lib/closeio/paginated_list.rb +0 -27
  43. data/lib/closeio/railtie.rb +0 -12
  44. data/lib/closeio/saved_search.rb +0 -7
  45. data/lib/closeio/status_report.rb +0 -11
  46. data/lib/closeio/task.rb +0 -3
  47. data/lib/closeio/user.rb +0 -7
data/.document DELETED
@@ -1,5 +0,0 @@
1
- README.rdoc
2
- lib/**/*.rb
3
- bin/*
4
- features/**/*.feature
5
- LICENSE
@@ -1,20 +0,0 @@
1
- module Closeio
2
- class ActivityReport < Base
3
- attr_reader :date_start, :date_end, :user_id
4
-
5
- def initialize(org_id, date_start, date_end, user_id=nil)
6
- @path = "/report/activity/#{org_id}"
7
- @date_start = date_start
8
- @date_end = date_end
9
- @user_id = user_id
10
- end
11
-
12
- def run
13
- query_params = {date_start: date_start, date_end: date_end}
14
- query_params.merge!(user_id: user_id) if user_id
15
-
16
- get("#{@path}/", query: query_params)
17
- end
18
-
19
- end
20
- end
data/lib/closeio/base.rb DELETED
@@ -1,92 +0,0 @@
1
- module Closeio
2
- class Base < OpenStruct
3
-
4
- include HTTParty
5
- base_uri 'https://app.close.io/api/v1'
6
- headers 'Content-Type' => 'application/json'
7
- #debug_output $stdout
8
- format :json
9
-
10
- extend Forwardable
11
- def_delegators 'self.class', :delete, :get, :post, :put, :resource_path, :bad_response
12
-
13
- attr_reader :data
14
-
15
- def initialize(attrs={})
16
- if attrs['data']
17
- super attrs['data']
18
- else
19
- super Hash[attrs]
20
- end
21
- end
22
-
23
- def save
24
- put "#{resource_path}#{self.id}/", body: self.to_h.to_json
25
- end
26
-
27
- class << self
28
- def descendants
29
- ObjectSpace.each_object(Class).select { |klass| klass < self }
30
- end
31
-
32
- def configure(api_key)
33
- @default_options.merge!(basic_auth: {
34
- username: api_key,
35
- password: ''
36
- })
37
- end
38
-
39
- def bad_response(response)
40
- raise "Unauthorized" if response.values.include? "Unauthorized"
41
- raise response.inspect
42
- end
43
-
44
- def all(response=nil, opts={})
45
- res = response || get(resource_path, opts)
46
-
47
- if res.success?
48
- res['data'].nil? ? [] : res['data'].map{|obj| new(obj)}
49
- else
50
- bad_response(res)
51
- end
52
- end
53
-
54
- # Closeio::Lead.create name: "Bluth Company", contacts: [{name: "Buster Bluth", emails: [{email: "cartographer@bluthcompany.com"}]}]
55
- def create(opts={})
56
- res = post(resource_path, body: opts.to_json)
57
- res.success? ? new(res) : bad_response(res)
58
- end
59
-
60
- #
61
- # Closeio::Lead.update '39292', name: "Bluth Company", contacts: [{name: "Buster Bluth", emails: [{email: "cartographer@bluthcompany.com"}]}]
62
- #
63
- def update(id, opts={})
64
- put "#{resource_path}#{id}/", body: opts.to_json
65
- end
66
-
67
- def destroy(id)
68
- delete "#{resource_path}#{id}/"
69
- end
70
-
71
- def find(id)
72
- res = get "#{resource_path}#{id}/"
73
- res.ok? ? new(res) : bad_response(res)
74
- end
75
-
76
- def where(opts={})
77
- res = get(resource_path, query: opts)
78
-
79
- if res.success?
80
- res['data'].nil? ? [] : res['data'].map{|obj| new(obj)}
81
- else
82
- bad_response res
83
- end
84
- end
85
-
86
- def resource_path
87
- klass = name.split('::').last.gsub(/([a-z\d])([A-Z])/,'\1_\2').downcase
88
- return "/#{klass}/"
89
- end
90
- end
91
- end
92
- end
@@ -1,25 +0,0 @@
1
- module Closeio
2
- class BulkAction < Base
3
- def initialize(query, value)
4
- @query = query
5
- @value = value
6
- @path = "#{resource_path}edit/"
7
- end
8
-
9
- def clear_custom_field
10
- post(@path, body: {
11
- query: @query,
12
- type: "clear_custom_field",
13
- custom_field_name: @value}.to_json
14
- )
15
- end
16
-
17
- def set_lead_status
18
- post(@path, body: {
19
- query: @query,
20
- type: "set_lead_status",
21
- lead_status_id: @value}.to_json
22
- )
23
- end
24
- end
25
- end
@@ -1,23 +0,0 @@
1
- module Closeio
2
- module Config
3
-
4
- class << self
5
- attr_accessor :config
6
- attr_accessor :api_key
7
- end
8
-
9
- %w(api_key).each do |method_name|
10
- define_singleton_method(method_name) do
11
- @config.fetch(method_name)
12
- end
13
- define_singleton_method("#{method_name}=") do |value|
14
- if @config.blank?
15
- @config = {method_name => value}
16
- else
17
- @config[method_name] = value
18
- end
19
- end
20
- end
21
-
22
- end
23
- end
@@ -1,3 +0,0 @@
1
- module Closeio
2
- class Contact < Base; end
3
- end
@@ -1,8 +0,0 @@
1
- module Closeio
2
- class CustomField < Base
3
-
4
- def self.resource_path
5
- return "/custom_fields/lead/"
6
- end
7
- end
8
- end
@@ -1,15 +0,0 @@
1
- module Closeio
2
- class CustomReport < Base
3
- def self.resource_path
4
- return "/report/custom/"
5
- end
6
-
7
- def self.search(organization_id, opt={})
8
- get "#{resource_path}#{organization_id}/", query: opts
9
- end
10
-
11
- def self.leads organization_id, opts={}
12
- get "#{resource_path}lead/#{organization_id}/", query: opts
13
- end
14
- end
15
- end
@@ -1,8 +0,0 @@
1
- module Closeio
2
- class EmailActivity < Base
3
-
4
- def self.resource_path
5
- return "/activity/email/"
6
- end
7
- end
8
- end
@@ -1,3 +0,0 @@
1
- module Closeio
2
- class EmailTemplate < Base; end
3
- end
data/lib/closeio/lead.rb DELETED
@@ -1,28 +0,0 @@
1
- module Closeio
2
- class Lead < Base
3
- #
4
- # Options: '_limit' => 1000, 'query' => 'custom.status:2'
5
- #
6
- def self.where opts={}
7
- res = get(resource_path, query: opts)
8
-
9
- if res.success?
10
- res['data'].nil? ? [] : res['data'].map{|obj| new(obj)}
11
- else
12
- bad_response res
13
- end
14
- end
15
-
16
- def emails
17
- Closeio::EmailActivity.where lead_id: self.id
18
- end
19
-
20
- def notes
21
- Closeio::NoteActivity.where lead_id: self.id
22
- end
23
-
24
- def contact
25
- self.contacts.first
26
- end
27
- end
28
- end
@@ -1,7 +0,0 @@
1
- module Closeio
2
- class LeadStatus < Base
3
- def self.resource_path
4
- return "/status/lead/"
5
- end
6
- end
7
- end
@@ -1,8 +0,0 @@
1
- module Closeio
2
- class NoteActivity < Base
3
-
4
- def self.resource_path
5
- return "/activity/note/"
6
- end
7
- end
8
- end
@@ -1,15 +0,0 @@
1
- module Closeio
2
- class Opportunity < Base
3
-
4
- def self.where opts={}
5
- res = get(resource_path, query: opts)
6
-
7
- if res.success?
8
- res['data'].nil? ? [] : res['data'].map{|obj| new(obj)}
9
- else
10
- bad_response res
11
- end
12
- end
13
-
14
- end
15
- end
@@ -1,7 +0,0 @@
1
- module Closeio
2
- class OpportunityStatus < Base
3
- def self.resource_path
4
- return "/status/opportunity/"
5
- end
6
- end
7
- end
@@ -1,8 +0,0 @@
1
- module Closeio
2
- class Organization < Base
3
-
4
- def users
5
- self.memberships
6
- end
7
- end
8
- end
@@ -1,27 +0,0 @@
1
- module Closeio
2
- class PaginatedList < ::Array
3
- attr_reader :total, :pages, :per_page, :page
4
- def initialize(results)
5
- @total = results['total']
6
- @pages = results['pages']
7
- @per_page = results['per_page']
8
- @page = results['page']
9
-
10
- result_key, result_class =
11
- if results.has_key?('shots')
12
- ['shots', Closeio::Shot]
13
- elsif results.has_key?('lead')
14
- ['leads', Closeio::Lead]
15
- else
16
- ['comments', Closeio::Comment]
17
- end
18
-
19
- super((results[result_key] || []).map { |attrs| result_class.new attrs })
20
- end
21
-
22
- def inspect
23
- ivar_str = instance_variables.map {|iv| "#{iv}=#{instance_variable_get(iv).inspect}"}.join(", ")
24
- "#<#{self.class.inspect} #{ivar_str}, @contents=#{super}>"
25
- end
26
- end
27
- end
@@ -1,12 +0,0 @@
1
- module Closeio
2
- class Railtie < Rails::Railtie
3
-
4
- initializer "setup closeio" do
5
- config_file = Rails.root.join("config", "closeio.yml")
6
- if config_file.file?
7
- Closeio::Config.config = YAML.load(ERB.new(config_file.read).result)[Rails.env]
8
- Closeio::Base.basic_auth Closeio::Config.api_key, ''
9
- end
10
- end
11
- end
12
- end
@@ -1,7 +0,0 @@
1
- module Closeio
2
- class SavedSearch < Base
3
- def leads
4
- Closeio::Lead.where query: self.query
5
- end
6
- end
7
- end
@@ -1,11 +0,0 @@
1
- module Closeio
2
- class StatusReport < Base
3
- def self.resource_path
4
- return "/report/statuses/lead/"
5
- end
6
-
7
- def self.leads organization_id, opts={}
8
- get "#{resource_path}#{organization_id}/", query: opts
9
- end
10
- end
11
- end
data/lib/closeio/task.rb DELETED
@@ -1,3 +0,0 @@
1
- module Closeio
2
- class Task < Base; end
3
- end
data/lib/closeio/user.rb DELETED
@@ -1,7 +0,0 @@
1
- module Closeio
2
- class User < Base
3
- def self.me
4
- get "/me"
5
- end
6
- end
7
- end