contactually-api 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 749467e599e692c5cc21a49444d12055f0ca31b7
4
- data.tar.gz: 492eb3805a030a9921e75d4b8284388675f37817
3
+ metadata.gz: ee398da691add3f2fe14f48f1bfe6df4fd8ccc03
4
+ data.tar.gz: 07a3ad39c3145dd57d8ea38157de6a2a5f28c18f
5
5
  SHA512:
6
- metadata.gz: 6042bbafb8b6c2df1747d3c6685795d1d90fa1823287cbda53bf436dc193d03649d308235674c2d37bf493554927c5d17539b35bb02196624494608376206a47
7
- data.tar.gz: 9f182641b3031f9f08f2b6fb1e2160aaf346e44b0f704a3c7b5405ae05ad9a53ef0e28b788b7ed1a3f5028ed622a01db091b55eed0f4fe465dbce18d03ea6d7a
6
+ metadata.gz: 954b718ce25a9ced2f79a4f9763368d1a6c86630ca0bb0f0aa52f45734d65e31547fc7158c122eba2ea92932ad465b1f4fc024dae7ffb9ef26aaf054fe5f4359
7
+ data.tar.gz: 57c10868f0545d74c9964713552388dfccef93408ed5bbb480340d9b49b85dbd6672762af1712ad390344d978b2b9b359885107c1d53d8dba4e8df348a4cf078
data/README.md CHANGED
@@ -1,9 +1,10 @@
1
1
  # Contactually-API
2
2
 
3
+ [![Code Climate](https://codeclimate.com/github/railslove/contactually-api/badges/gpa.svg)](https://codeclimate.com/github/railslove/contactually-api)
3
4
  [![Build
4
5
  Status](https://travis-ci.org/railslove/contactually-api.svg?branch=master)](https://travis-ci.org/railslove/contactually-api)
5
6
 
6
- TODO: Write a gem description
7
+ This is a simple API Wrapper for the contactually API. It is not feature complete, as it does not support all available API endpoints yet, but I guess for most use cases this will be fine. Feel free to contribute!
7
8
 
8
9
  ## Installation
9
10
 
@@ -34,22 +35,38 @@ The available configuration options are:
34
35
 
35
36
  Configuration goes as follows:
36
37
 
38
+ ```ruby
37
39
  Contactually.configure do |c|
38
40
  c.api_key = "YOURKEY"
39
41
  c.contactually_url = "URL"
40
42
  end
43
+ ```
41
44
 
42
45
  #### How to use the gem
43
46
 
47
+ ```ruby
44
48
  contactually = Contactually::API.new
45
49
  contacts = contactually.contacts.index
50
+ # => [#<Contactually::Contact id=1234, ...>, #<Contactually::Contact id=1235, ...>, ...]
46
51
  notes = contactually.notes.index
52
+ # => [#<Contactually::Note id=2345, ...>, #<Contactually::Note id=2346, ...>, ...]
47
53
  groupings = contactually.groupings.index
54
+ # => [#<Contactually::Grouping id=3456, ...>, #<Contactually::Grouping id=3457, ...>, ...]
48
55
 
49
56
  contact = { contact: { first_name: 'Jane', last_name: 'Doe', ... } }
50
57
  contactually.contacts.create(contact)
51
-
52
- ...
58
+ # => #<Contactually::Contact id=9876, first_name='Jane', last_name='Doe', ...>
59
+ ```
60
+
61
+ Implemented endpoints are:
62
+
63
+ * Accounts
64
+ * Contact Groupings
65
+ * Contacts
66
+ * Contents
67
+ * Groupings
68
+ * Notes
69
+ * Tasks
53
70
 
54
71
  The API is documented here: [Contactually API Docs](http://developers.contactually.com/docs/)
55
72
 
@@ -7,25 +7,16 @@ module Contactually
7
7
 
8
8
  def index(params = {})
9
9
  hash = @master.call('accounts.json', :get, params)
10
- accounts_hash_to_objects(hash)
10
+ Contactually::Utils.accounts_hash_to_objects(hash)
11
11
  end
12
12
 
13
13
  def show(id, params = {})
14
14
  hash = @master.call("accounts/#{id}.json", :get, params)
15
- AccountRepresenter.new(Account.new).from_hash(hash)
15
+ Contactually::Utils.build_account(hash)
16
16
  end
17
17
 
18
18
  def destroy(id, params = {})
19
19
  @master.call("accounts/#{id}.json", :delete, params)
20
20
  end
21
-
22
- private
23
-
24
- def accounts_hash_to_objects(hash)
25
- hash['accounts'].inject([]) do |arr, account|
26
- arr << AccountRepresenter.new(Account.new).from_hash(account)
27
- end
28
- end
29
-
30
21
  end
31
22
  end
@@ -6,7 +6,7 @@ module Contactually
6
6
 
7
7
  def create(id, params = {})
8
8
  hash = @master.call("contacts/#{id}/groupings.json", :post, params)
9
- GroupingRepresenter.new(Grouping.new).from_hash(hash)
9
+ Contactually::Utils.build_grouping(hash)
10
10
  end
11
11
 
12
12
  def destroy(id, grouping_id, params = {})
@@ -6,7 +6,7 @@ module Contactually
6
6
 
7
7
  def create(params = {})
8
8
  hash = @master.call('contacts.json', :post, params)
9
- ContactRepresenter.new(Contact.new).from_hash(hash)
9
+ Contactually::Utils.build_contact(hash)
10
10
  end
11
11
 
12
12
  def destroy(id, params = {})
@@ -19,12 +19,12 @@ module Contactually
19
19
 
20
20
  def show(id, params = {})
21
21
  hash = @master.call("contacts/#{id}.json", :get, params)
22
- ContactRepresenter.new(Contact.new).from_hash(hash)
22
+ Contactually::Utils.build_contact(hash)
23
23
  end
24
24
 
25
25
  def merge(params = {})
26
26
  hash = @master.call('contacts/merge.json', :post, params)
27
- ContactRepresenter.new(Contact.new).from_hash(hash)
27
+ Contactually::Utils.build_contact(hash)
28
28
  end
29
29
 
30
30
  def tags(id, params = {})
@@ -38,20 +38,12 @@ module Contactually
38
38
 
39
39
  def index(params = {})
40
40
  hash = @master.call('contacts.json', :get, params)
41
- contacts_hash_to_objects(hash)
41
+ Contactually::Utils.contacts_hash_to_objects(hash)
42
42
  end
43
43
 
44
44
  def search(params = {})
45
45
  hash = @master.call('contacts/search.json', :get, params)
46
- contacts_hash_to_objects(hash)
47
- end
48
-
49
- private
50
-
51
- def contacts_hash_to_objects(hash)
52
- hash['contacts'].inject([]) do |arr, contact|
53
- arr << ContactRepresenter.new(Contact.new).from_hash(contact)
54
- end
46
+ Contactually::Utils.contacts_hash_to_objects(hash)
55
47
  end
56
48
  end
57
49
  end
@@ -6,12 +6,12 @@ module Contactually
6
6
 
7
7
  def create(params = {})
8
8
  hash = @master.call('contents.json', :post, params)
9
- ContentRepresenter.new(Content.new).from_hash(hash)
9
+ Contactually::Utils.build_content(hash)
10
10
  end
11
11
 
12
12
  def index(params = {})
13
13
  hash = @master.call('contents.json', :get, params)
14
- contents_hash_to_objects(hash)
14
+ Contactually::Utils.contents_hash_to_objects(hash)
15
15
  end
16
16
 
17
17
  def destroy(id, params = {})
@@ -20,19 +20,11 @@ module Contactually
20
20
 
21
21
  def show(id, params = {})
22
22
  hash = @master.call("contents/#{id}.json", :get, params)
23
- ContentRepresenter.new(Content.new).from_hash(hash)
23
+ Contactually::Utils.build_content(hash)
24
24
  end
25
25
 
26
26
  def update(id, params = {})
27
27
  @master.call("contents/#{id}.json", :put, params)
28
28
  end
29
-
30
- private
31
-
32
- def contents_hash_to_objects(hash)
33
- hash['contents'].inject([]) do |arr, content|
34
- arr << ContentRepresenter.new(Content.new).from_hash(content)
35
- end
36
- end
37
29
  end
38
30
  end
@@ -6,17 +6,17 @@ module Contactually
6
6
 
7
7
  def create(params = {})
8
8
  hash = @master.call('groupings.json', :post, params)
9
- GroupingRepresenter.new(Grouping.new).from_hash(hash)
9
+ Contactually::Utils.build_grouping(hash)
10
10
  end
11
11
 
12
12
  def index(params = {})
13
13
  hash = @master.call('groupings.json', :get, params)
14
- groupings_hash_to_objects(hash)
14
+ Contactually::Utils.groupings_hash_to_objects(hash)
15
15
  end
16
16
 
17
17
  def minimal_index(params = {})
18
18
  hash = @master.call('groupings/minimal_index.json', :get, params)
19
- GroupingRepresenter.new(Grouping.new).from_hash(hash)
19
+ Contactually::Utils.build_grouping(hash)
20
20
  end
21
21
 
22
22
  def destroy(id, params = {})
@@ -25,25 +25,17 @@ module Contactually
25
25
 
26
26
  def show(id, params = {})
27
27
  hash = @master.call("groupings/#{id}.json", :get, params)
28
- GroupingRepresenter.new(Grouping.new).from_hash(hash)
28
+ Contactually::Utils.build_grouping(hash)
29
29
  end
30
30
 
31
31
  def update(id, params = {})
32
32
  hash = @master.call("groupings/#{id}.json", :put, params)
33
- GroupingRepresenter.new(Grouping.new).from_hash(hash)
33
+ Contactually::Utils.build_grouping(hash)
34
34
  end
35
35
 
36
36
  def statistics(id, params = {})
37
37
  hash = @master.call("groupings/#{id}/statistics.json", :get, params)
38
- GroupingStatisticsRepresenter.new(GroupingStatistics.new).from_hash(hash)
39
- end
40
-
41
- private
42
-
43
- def groupings_hash_to_objects(hash)
44
- hash['groupings'].inject([]) do |arr, grouping|
45
- arr << GroupingRepresenter.new(Grouping.new).from_hash(grouping)
46
- end
38
+ Contactually::Utils.build_grouping_statistic(hash)
47
39
  end
48
40
  end
49
41
  end
@@ -6,17 +6,17 @@ module Contactually
6
6
 
7
7
  def index(params = {})
8
8
  hash = @master.call('notes.json', :get, params)
9
- notes_hash_to_objects(hash)
9
+ Contactually::Utils.notes_hash_to_objects(hash)
10
10
  end
11
11
 
12
12
  def show(id, params = {})
13
13
  hash = @master.call("notes/#{id}.json", :get, params)
14
- NoteRepresenter.new(Note.new).from_hash(hash)
14
+ Contactually::Utils.build_note(hash)
15
15
  end
16
16
 
17
17
  def create(params = {})
18
18
  hash = @master.call('notes.json', :post, params)
19
- NoteRepresenter.new(Note.new).from_hash(hash)
19
+ Contactually::Utils.build_note(hash)
20
20
  end
21
21
 
22
22
  def destroy(id, params = {})
@@ -25,15 +25,7 @@ module Contactually
25
25
 
26
26
  def update(id, params = {})
27
27
  hash = @master.call("notes/#{id}.json", :put, params)
28
- NoteRepresenter.new(Note.new).from_hash(hash)
29
- end
30
-
31
- private
32
-
33
- def notes_hash_to_objects(hash)
34
- hash['notes'].inject([]) do |arr, note|
35
- arr << NoteRepresenter.new(Note.new).from_hash(note)
36
- end
28
+ Contactually::Utils.build_note(hash)
37
29
  end
38
30
  end
39
31
  end
@@ -2,12 +2,14 @@ module Contactually
2
2
  class Account < OpenStruct
3
3
  end
4
4
 
5
- class AccountRepresenter < Roar::Decorator
6
- include Roar::Representer::JSON
7
- property :id
8
- property :username
9
- property :remote_id
10
- property :type
11
- property :disabled_at
5
+ module Representer
6
+ class AccountRepresenter < Roar::Decorator
7
+ include Roar::Representer::JSON
8
+ property :id
9
+ property :username
10
+ property :remote_id
11
+ property :type
12
+ property :disabled_at
13
+ end
12
14
  end
13
15
  end
@@ -2,45 +2,47 @@ module Contactually
2
2
  class Contact < OpenStruct
3
3
  end
4
4
 
5
- class ContactRepresenter < Roar::Decorator
6
- include Roar::Representer::JSON
7
- property :id
8
- property :user_id
9
- property :first_name
10
- property :last_name
11
- property :full_name
12
- property :initials
13
- property :title
14
- property :company
15
- property :email
16
- property :avatar
17
- property :avatar_url
18
- property :last_contacted
19
- property :visible
20
- property :twitter
21
- property :facebook_url
22
- property :linkedin_url
23
- property :first_contacted
24
- property :created_at
25
- property :updated_at
26
- property :hits
27
- property :team_parent_id
28
- property :snoozed_at
29
- property :snooze_days
30
- property :email_addresses
31
- property :tags
32
- property :contact_status
33
- property :team_last_contacted
34
- property :team_last_contacted_by
35
- property :phone_numbers
36
- property :addresses
37
- property :social_profiles
38
- property :websites
39
- property :custom_fields
40
- property :sent
41
- property :received
42
- property :link
43
- property :content
44
- collection :groupings, extend: GroupingRepresenter, class: Grouping
5
+ module Representer
6
+ class ContactRepresenter < Roar::Decorator
7
+ include Roar::Representer::JSON
8
+ property :id
9
+ property :user_id
10
+ property :first_name
11
+ property :last_name
12
+ property :full_name
13
+ property :initials
14
+ property :title
15
+ property :company
16
+ property :email
17
+ property :avatar
18
+ property :avatar_url
19
+ property :last_contacted
20
+ property :visible
21
+ property :twitter
22
+ property :facebook_url
23
+ property :linkedin_url
24
+ property :first_contacted
25
+ property :created_at
26
+ property :updated_at
27
+ property :hits
28
+ property :team_parent_id
29
+ property :snoozed_at
30
+ property :snooze_days
31
+ property :email_addresses
32
+ property :tags
33
+ property :contact_status
34
+ property :team_last_contacted
35
+ property :team_last_contacted_by
36
+ property :phone_numbers
37
+ property :addresses
38
+ property :social_profiles
39
+ property :websites
40
+ property :custom_fields
41
+ property :sent
42
+ property :received
43
+ property :link
44
+ property :content
45
+ collection :groupings, extend: GroupingRepresenter, class: Grouping
46
+ end
45
47
  end
46
48
  end
@@ -2,15 +2,17 @@ module Contactually
2
2
  class Content < OpenStruct
3
3
  end
4
4
 
5
- class ContentRepresenter < Roar::Decorator
6
- include Roar::Representer::JSON
7
- property :id
8
- property :user_id
9
- property :url
10
- property :title
11
- property :description
12
- property :article
13
- property :original_content_id
14
- collection :groupings, extend: GroupingRepresenter, class: Grouping
5
+ module Representer
6
+ class ContentRepresenter < Roar::Decorator
7
+ include Roar::Representer::JSON
8
+ property :id
9
+ property :user_id
10
+ property :url
11
+ property :title
12
+ property :description
13
+ property :article
14
+ property :original_content_id
15
+ collection :groupings, extend: GroupingRepresenter, class: Grouping
16
+ end
15
17
  end
16
18
  end
@@ -2,27 +2,29 @@ module Contactually
2
2
  class Grouping < OpenStruct
3
3
  end
4
4
 
5
- class GroupingRepresenter < Roar::Decorator
6
- include Roar::Representer::JSON
7
- property :id
8
- property :type
9
- property :name
10
- property :stub
11
- property :user_id
12
- property :domain_id
13
- property :editable
14
- property :conversable
15
- property :locked
16
- property :derived_from_id
17
- property :created_at
18
- property :updated_at
19
- property :has_followups
20
- property :num_days_to_followup
21
- property :program_id
22
- property :objective
23
- property :sort_order
24
- property :accounts
25
- property :number_of_contacts
26
- property :goal
5
+ module Representer
6
+ class GroupingRepresenter < Roar::Decorator
7
+ include Roar::Representer::JSON
8
+ property :id
9
+ property :type
10
+ property :name
11
+ property :stub
12
+ property :user_id
13
+ property :domain_id
14
+ property :editable
15
+ property :conversable
16
+ property :locked
17
+ property :derived_from_id
18
+ property :created_at
19
+ property :updated_at
20
+ property :has_followups
21
+ property :num_days_to_followup
22
+ property :program_id
23
+ property :objective
24
+ property :sort_order
25
+ property :accounts
26
+ property :number_of_contacts
27
+ property :goal
28
+ end
27
29
  end
28
30
  end
@@ -0,0 +1,14 @@
1
+ module Contactually
2
+ class GroupingStatistic < OpenStruct
3
+ end
4
+
5
+ module Representer
6
+ class GroupingStatisticRepresenter < Roar::Decorator
7
+ include Roar::Representer::JSON
8
+ property :messages_sent
9
+ property :messages_received
10
+ property :status
11
+ collection :contacts, extend: ContactRepresenter, class: Contact
12
+ end
13
+ end
14
+ end
@@ -2,12 +2,14 @@ module Contactually
2
2
  class Note < OpenStruct
3
3
  end
4
4
 
5
- class NoteRepresenter < Roar::Decorator
6
- include Roar::Representer::JSON
7
- property :id
8
- property :body
9
- property :contact_id
10
- property :timestamp
11
- property :user_id
5
+ module Representer
6
+ class NoteRepresenter < Roar::Decorator
7
+ include Roar::Representer::JSON
8
+ property :id
9
+ property :body
10
+ property :contact_id
11
+ property :timestamp
12
+ property :user_id
13
+ end
12
14
  end
13
15
  end
@@ -2,18 +2,20 @@ module Contactually
2
2
  class Task < OpenStruct
3
3
  end
4
4
 
5
- class TaskRepresenter < Roar::Decorator
6
- include Roar::Representer::JSON
7
- property :id
8
- property :title
9
- property :due_date
10
- property :completed_at
11
- property :deleted_at
12
- property :is_follow_up
13
- property :last_contacted
14
- property :contact_id
15
- property :ignored
16
- property :completed_via
17
- property :approval_data
5
+ module Representer
6
+ class TaskRepresenter < Roar::Decorator
7
+ include Roar::Representer::JSON
8
+ property :id
9
+ property :title
10
+ property :due_date
11
+ property :completed_at
12
+ property :deleted_at
13
+ property :is_follow_up
14
+ property :last_contacted
15
+ property :contact_id
16
+ property :ignored
17
+ property :completed_via
18
+ property :approval_data
19
+ end
18
20
  end
19
21
  end
@@ -6,7 +6,44 @@ module Contactually
6
6
 
7
7
  def show(id, params = {})
8
8
  hash = @master.call("tasks/#{id}.json", :get, params)
9
- TaskRepresenter.new(Task.new).from_hash(hash)
9
+ Contactually::Utils.build_task(hash)
10
+ end
11
+
12
+ def complete(id, params = {})
13
+ hash = @master.call("tasks/#{id}/complete.json", :post, params)
14
+ Contactually::Utils.build_task(hash)
15
+ end
16
+
17
+ def create(params = {})
18
+ hash = @master.call('tasks.json', :post, params)
19
+ Contactually::Utils.build_task(hash)
20
+ end
21
+
22
+ def destroy(id, params = {})
23
+ @master.call("tasks/#{id}.json", :delete, params)
24
+ end
25
+
26
+ def generate_followups(params = {})
27
+ @master.call('tasks/generate_followups.json', :post, params)
28
+ end
29
+
30
+ def ignore(id, params = {})
31
+ hash = @master.call("tasks/#{id}/ignore.json", :post, params)
32
+ Contactually::Utils.build_task(hash)
33
+ end
34
+
35
+ def index(params = {})
36
+ hash = @master.call('tasks.json', :get, params)
37
+ Contactually::Utils.tasks_hash_to_objects(hash)
38
+ end
39
+
40
+ def snooze(id, params = {})
41
+ @master.call("tasks/#{id}/snooze.json", :post, params)
42
+ end
43
+
44
+ def update(id, params = {})
45
+ hash = @master.call("tasks/#{id}.json", :put, params)
46
+ Contactually::Utils.build_task(hash)
10
47
  end
11
48
  end
12
49
  end
@@ -0,0 +1,44 @@
1
+ module Contactually
2
+ class Utils
3
+
4
+ class << self
5
+ def method_missing(m, *args)
6
+ case m
7
+ when /^(\w*)_hash_to_objects/ then
8
+ hash_to_objects($1, *args)
9
+ when /^build_(\w*)/ then
10
+ build_object($1, *args)
11
+ else
12
+ super(m, *args)
13
+ end
14
+ end
15
+
16
+ def respond_to?(m, *args)
17
+ case m
18
+ when /^(\w*)_hash_to_objects/ then
19
+ true
20
+ when /^build_(\w*)/ then
21
+ true
22
+ else
23
+ super(m, *args)
24
+ end
25
+ end
26
+
27
+ private
28
+
29
+ def hash_to_objects(type, hash)
30
+ representer_class = "Contactually::Representer::#{type.classify}Representer".constantize
31
+ object_class = "Contactually::#{type.classify}".constantize
32
+ hash[type].inject([]) do |arr, obj|
33
+ arr << representer_class.new(object_class.new).from_hash(obj)
34
+ end
35
+ end
36
+
37
+ def build_object(type, hash)
38
+ representer_class = "Contactually::Representer::#{type.classify}Representer".constantize
39
+ object_class = "Contactually::#{type.classify}".constantize
40
+ representer_class.new(object_class.new).from_hash(hash)
41
+ end
42
+ end
43
+ end
44
+ end
@@ -1,3 +1,3 @@
1
1
  module Contactually
2
- VERSION = "0.0.1"
2
+ VERSION = "0.0.2"
3
3
  end
@@ -1,4 +1,5 @@
1
1
  require 'active_support/configurable'
2
+ require 'active_support/inflector'
2
3
  require 'faraday'
3
4
  require 'json'
4
5
  require 'roar/decorator'
@@ -6,6 +7,7 @@ require 'roar/representer/json'
6
7
 
7
8
  require 'contactually/version'
8
9
  require 'contactually/errors'
10
+ require 'contactually/utils'
9
11
 
10
12
  require 'contactually/middleware/error_detector'
11
13
 
@@ -13,7 +15,7 @@ require 'contactually/representer/grouping_representer'
13
15
  require 'contactually/representer/account_representer'
14
16
  require 'contactually/representer/contact_representer'
15
17
  require 'contactually/representer/content_representer'
16
- require 'contactually/representer/grouping_statistics_representer'
18
+ require 'contactually/representer/grouping_statistic_representer'
17
19
  require 'contactually/representer/note_representer'
18
20
  require 'contactually/representer/task_representer'
19
21
 
@@ -0,0 +1,38 @@
1
+ {
2
+ "count": 1,
3
+ "total_count": 1,
4
+ "tasks": [
5
+ {
6
+ "id": 123123,
7
+ "title": "Lolokopter",
8
+ "due_date": "2015-10-01T00:00:00Z",
9
+ "interaction_type": null,
10
+ "completed_at": null,
11
+ "deleted_at": null,
12
+ "is_follow_up": false,
13
+ "last_contacted": null,
14
+ "contact_id": 1234,
15
+ "ignored": null,
16
+ "completed_via": null,
17
+ "user_id": 12345,
18
+ "approval_data": {
19
+ "approval_type": false,
20
+ "approval_text": false,
21
+ "approval_url": false,
22
+ "approval_template": false,
23
+ "approval_account_id": false
24
+ },
25
+ "contact_program_step_id": null,
26
+ "unresponded_followup_id": null,
27
+ "user_bucket": {
28
+ "id": 12312,
29
+ "name": "Colleague"
30
+ }
31
+ }
32
+ ],
33
+ "weekly_progress": [
34
+ 0,
35
+ 7
36
+ ],
37
+ "on_due_date": true
38
+ }
@@ -94,7 +94,7 @@ describe Contactually::Groupings do
94
94
  it 'returns statistics object' do
95
95
  json = File.read(File.join(File.dirname(__FILE__), "fixtures/groupings_statistics.json"))
96
96
  allow(@master).to receive(:call).with('groupings/1/statistics.json', :get, { foo: :bar }).and_return(JSON.load(json))
97
- expect(subject.statistics(1, { foo: :bar })).to be_kind_of Contactually::GroupingStatistics
97
+ expect(subject.statistics(1, { foo: :bar })).to be_kind_of Contactually::GroupingStatistic
98
98
  end
99
99
  end
100
100
  end
data/spec/tasks_spec.rb CHANGED
@@ -33,4 +33,103 @@ describe Contactually::Tasks do
33
33
  end
34
34
  end
35
35
 
36
+ describe '#complete' do
37
+ it 'calls the api with correct params' do
38
+ json = File.read(File.join(File.dirname(__FILE__),"fixtures/task.json"))
39
+ allow(@master).to receive(:call).with('tasks/1/complete.json', :post, { foo: :bar }).and_return(JSON.load(json))
40
+ subject.complete(1, { foo: :bar })
41
+ expect(@master).to have_received(:call)
42
+ end
43
+
44
+ it 'returns a task' do
45
+ json = File.read(File.join(File.dirname(__FILE__),"fixtures/task.json"))
46
+ allow(@master).to receive(:call).with('tasks/1/complete.json', :post, { foo: :bar }).and_return(JSON.load(json))
47
+ expect(subject.complete(1, { foo: :bar })).to be_kind_of Contactually::Task
48
+ end
49
+ end
50
+
51
+ describe '#create' do
52
+ it 'calls the api with correct params' do
53
+ json = File.read(File.join(File.dirname(__FILE__),"fixtures/task.json"))
54
+ allow(@master).to receive(:call).with('tasks.json', :post, { foo: :bar }).and_return(JSON.load(json))
55
+ subject.create({ foo: :bar })
56
+ expect(@master).to have_received(:call)
57
+ end
58
+
59
+ it 'returns a new task' do
60
+ json = File.read(File.join(File.dirname(__FILE__),"fixtures/task.json"))
61
+ allow(@master).to receive(:call).with('tasks.json', :post, { foo: :bar }).and_return(JSON.load(json))
62
+ expect(subject.create({ foo: :bar })).to be_kind_of Contactually::Task
63
+ end
64
+ end
65
+
66
+ describe '#update' do
67
+ it 'calls the api with correct params' do
68
+ json = File.read(File.join(File.dirname(__FILE__),"fixtures/task.json"))
69
+ allow(@master).to receive(:call).with('tasks/1.json', :put, { foo: :bar }).and_return(JSON.load(json))
70
+ subject.update(1, { foo: :bar })
71
+ expect(@master).to have_received(:call)
72
+ end
73
+
74
+ it 'returns a new task' do
75
+ json = File.read(File.join(File.dirname(__FILE__),"fixtures/task.json"))
76
+ allow(@master).to receive(:call).with('tasks/1.json', :put, { foo: :bar }).and_return(JSON.load(json))
77
+ expect(subject.update(1, { foo: :bar })).to be_kind_of Contactually::Task
78
+ end
79
+ end
80
+
81
+ describe '#destroy' do
82
+ it 'calls the api with correct params' do
83
+ allow(@master).to receive(:call).with('tasks/1.json', :delete, { foo: :bar }).and_return(JSON.load('{ "deleted": true }'))
84
+ subject.destroy(1, { foo: :bar })
85
+ expect(@master).to have_received(:call)
86
+ end
87
+ end
88
+
89
+ describe '#generate_followups' do
90
+ it 'calls the api with correct params' do
91
+ allow(@master).to receive(:call).with('tasks/generate_followups.json', :post, { foo: :bar }).and_return(JSON.load('{ "deleted": true }'))
92
+ subject.generate_followups({ foo: :bar })
93
+ expect(@master).to have_received(:call)
94
+ end
95
+ end
96
+
97
+ describe '#generate_followups' do
98
+ it 'calls the api with correct params' do
99
+ allow(@master).to receive(:call).with('tasks/1/snooze.json', :post, { foo: :bar }).and_return(JSON.load('{ "snooze": true }'))
100
+ subject.snooze(1, { foo: :bar })
101
+ expect(@master).to have_received(:call)
102
+ end
103
+ end
104
+
105
+ describe '#ignore' do
106
+ it 'calls the api with correct params' do
107
+ json = File.read(File.join(File.dirname(__FILE__),"fixtures/task.json"))
108
+ allow(@master).to receive(:call).with('tasks/1/ignore.json', :post, { foo: :bar }).and_return(JSON.load(json))
109
+ subject.ignore(1, { foo: :bar })
110
+ expect(@master).to have_received(:call)
111
+ end
112
+
113
+ it 'returns a new task' do
114
+ json = File.read(File.join(File.dirname(__FILE__),"fixtures/task.json"))
115
+ allow(@master).to receive(:call).with('tasks/1/ignore.json', :post, { foo: :bar }).and_return(JSON.load(json))
116
+ expect(subject.ignore(1, { foo: :bar })).to be_kind_of Contactually::Task
117
+ end
118
+ end
119
+
120
+ describe '#index' do
121
+ it 'calls the api with correct params' do
122
+ allow(@master).to receive(:call).with('tasks.json', :get, { foo: :bar }).and_return({ 'tasks' => [] })
123
+ subject.index({ foo: :bar })
124
+ expect(@master).to have_received(:call)
125
+ end
126
+
127
+ it 'returns tasks from json response' do
128
+ json = File.read(File.join(File.dirname(__FILE__),"fixtures/tasks_index.json"))
129
+ allow(@master).to receive(:call).with('tasks.json', :get, {}).and_return(JSON.load(json))
130
+ expect(subject.index({})).to be_kind_of Array
131
+ expect(subject.index({})[0]).to be_kind_of Contactually::Task
132
+ end
133
+ end
134
+
36
135
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: contactually-api
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Johannes Heck
@@ -16,84 +16,84 @@ dependencies:
16
16
  requirements:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: 4.1.5
19
+ version: '4.1'
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
- version: 4.1.5
26
+ version: '4.1'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: faraday
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
31
  - - "~>"
32
32
  - !ruby/object:Gem::Version
33
- version: 0.9.0
33
+ version: '0.9'
34
34
  type: :runtime
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
38
  - - "~>"
39
39
  - !ruby/object:Gem::Version
40
- version: 0.9.0
40
+ version: '0.9'
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: roar
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
45
  - - "~>"
46
46
  - !ruby/object:Gem::Version
47
- version: 0.12.9
47
+ version: '0.12'
48
48
  type: :runtime
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
52
  - - "~>"
53
53
  - !ruby/object:Gem::Version
54
- version: 0.12.9
54
+ version: '0.12'
55
55
  - !ruby/object:Gem::Dependency
56
56
  name: pry-byebug
57
57
  requirement: !ruby/object:Gem::Requirement
58
58
  requirements:
59
- - - ">="
59
+ - - "~>"
60
60
  - !ruby/object:Gem::Version
61
- version: '0'
61
+ version: '2.0'
62
62
  type: :development
63
63
  prerelease: false
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
66
- - - ">="
66
+ - - "~>"
67
67
  - !ruby/object:Gem::Version
68
- version: '0'
68
+ version: '2.0'
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: rake
71
71
  requirement: !ruby/object:Gem::Requirement
72
72
  requirements:
73
- - - ">="
73
+ - - "~>"
74
74
  - !ruby/object:Gem::Version
75
- version: '0'
75
+ version: '10'
76
76
  type: :development
77
77
  prerelease: false
78
78
  version_requirements: !ruby/object:Gem::Requirement
79
79
  requirements:
80
- - - ">="
80
+ - - "~>"
81
81
  - !ruby/object:Gem::Version
82
- version: '0'
82
+ version: '10'
83
83
  - !ruby/object:Gem::Dependency
84
84
  name: rspec
85
85
  requirement: !ruby/object:Gem::Requirement
86
86
  requirements:
87
- - - ">="
87
+ - - "~>"
88
88
  - !ruby/object:Gem::Version
89
- version: '0'
89
+ version: '3'
90
90
  type: :development
91
91
  prerelease: false
92
92
  version_requirements: !ruby/object:Gem::Requirement
93
93
  requirements:
94
- - - ">="
94
+ - - "~>"
95
95
  - !ruby/object:Gem::Version
96
- version: '0'
96
+ version: '3'
97
97
  description: This is a simple wrapper for the contactually api. Try it!
98
98
  email:
99
99
  - johannes@railslove.com
@@ -118,10 +118,11 @@ files:
118
118
  - lib/contactually/representer/contact_representer.rb
119
119
  - lib/contactually/representer/content_representer.rb
120
120
  - lib/contactually/representer/grouping_representer.rb
121
- - lib/contactually/representer/grouping_statistics_representer.rb
121
+ - lib/contactually/representer/grouping_statistic_representer.rb
122
122
  - lib/contactually/representer/note_representer.rb
123
123
  - lib/contactually/representer/task_representer.rb
124
124
  - lib/contactually/tasks.rb
125
+ - lib/contactually/utils.rb
125
126
  - lib/contactually/version.rb
126
127
  - spec/accounts_spec.rb
127
128
  - spec/api_spec.rb
@@ -141,6 +142,7 @@ files:
141
142
  - spec/fixtures/note_destroy.json
142
143
  - spec/fixtures/notes_index.json
143
144
  - spec/fixtures/task.json
145
+ - spec/fixtures/tasks_index.json
144
146
  - spec/groupings_spec.rb
145
147
  - spec/notes_spec.rb
146
148
  - spec/spec_helper.rb
@@ -157,7 +159,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
157
159
  requirements:
158
160
  - - ">="
159
161
  - !ruby/object:Gem::Version
160
- version: '0'
162
+ version: '2.0'
161
163
  required_rubygems_version: !ruby/object:Gem::Requirement
162
164
  requirements:
163
165
  - - ">="
@@ -188,6 +190,7 @@ test_files:
188
190
  - spec/fixtures/note_destroy.json
189
191
  - spec/fixtures/notes_index.json
190
192
  - spec/fixtures/task.json
193
+ - spec/fixtures/tasks_index.json
191
194
  - spec/groupings_spec.rb
192
195
  - spec/notes_spec.rb
193
196
  - spec/spec_helper.rb
@@ -1,12 +0,0 @@
1
- module Contactually
2
- class GroupingStatistics < OpenStruct
3
- end
4
-
5
- class GroupingStatisticsRepresenter < Roar::Decorator
6
- include Roar::Representer::JSON
7
- property :messages_sent
8
- property :messages_received
9
- property :status
10
- collection :contacts, extend: ContactRepresenter, class: Contact
11
- end
12
- end