contactually-api 0.0.3 → 0.0.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 52c58a5aa6d6ecc6d612f0ae0366a5bce859ccf0
4
- data.tar.gz: 7c71f707ba29bb435b89f90601ac38345be21d19
3
+ metadata.gz: 5b229529b6cd9e6c9e1194c9b8f9dfd815716f59
4
+ data.tar.gz: 207a10352a62b760a13060c3d02f629adb65f9d6
5
5
  SHA512:
6
- metadata.gz: 879d68b4a16df5ded12212deb10abe89e79f27b11e0f1c219ff8b8625b631d064c7522ab3584c1cbf3cb95abc83f4b265a876eaffbadeb80be5c81b61689c593
7
- data.tar.gz: cf5a164d0ba56c6605150e21a00c64afdeea94d116c6de467e4b4636d7fb8da8d6238833176534598d3f113ca80948ae1791de2555711f003b976da65f2f11b6
6
+ metadata.gz: 7ea7125518a774970476ef75ae2bf4e94592cc8bb74c44bbdb98f2b885effd0e79850c3d261da2de334a899a77346326f3f1c900832ec8c6635d35086b77610b
7
+ data.tar.gz: 778405c57ad558e5c634b9608a429cdab695ad7f402ed07eb770dca04a4999f594fd80458de11f03f89d2a226be787be830aa427271a9f3417db2c15196339b4
@@ -19,6 +19,10 @@ module Contactually
19
19
  @notes ||= Contactually::Notes.new self
20
20
  end
21
21
 
22
+ def tasks
23
+ @tasks ||= Contactually::Tasks.new self
24
+ end
25
+
22
26
  def groupings
23
27
  @groupings ||= Contactually::Groupings.new self
24
28
  end
@@ -31,10 +35,14 @@ module Contactually
31
35
  @contact_groupings ||= Contactually::ContactGroupings.new self
32
36
  end
33
37
 
38
+ def contents
39
+ @contents ||= Contactually::Contents.new self
40
+ end
41
+
34
42
  def connection
35
43
  @connection ||= Faraday.new do |faraday|
36
- faraday.adapter Faraday.default_adapter
37
44
  faraday.headers['Content-Type'] = 'application/json'
45
+ faraday.adapter Faraday.default_adapter
38
46
  faraday.use Contactually::Middleware::ErrorDetector
39
47
  end
40
48
  end
@@ -12,6 +12,9 @@ module Contactually
12
12
  class DuplicatedContactError < Error
13
13
  end
14
14
 
15
+ class AuthenticationError < Error
16
+ end
17
+
15
18
  class APIError < Error
16
19
  end
17
20
 
@@ -3,7 +3,7 @@ module Contactually
3
3
  class ErrorDetector < Faraday::Middleware
4
4
 
5
5
  def call(env)
6
- @app.call(env).on_complete do
6
+ @app.call(env).on_complete do |env|
7
7
  unless (200..299).include? env[:status]
8
8
  cast_error(env[:body])
9
9
  end
@@ -18,9 +18,13 @@ module Contactually
18
18
  raise InvalidParametersError, body
19
19
  when /^We already have/ then
20
20
  raise DuplicatedContactError, body
21
+ when /^You need to sign in/ then
22
+ raise AuthenticationError, body
21
23
  else
22
24
  raise APIError, body
23
25
  end
26
+ rescue JSON::ParserError
27
+ raise APIError, body
24
28
  end
25
29
  end
26
30
  end
@@ -1,3 +1,3 @@
1
1
  module Contactually
2
- VERSION = "0.0.3"
2
+ VERSION = "0.0.4"
3
3
  end
@@ -2,6 +2,9 @@ require 'spec_helper'
2
2
 
3
3
  describe Contactually::Accounts do
4
4
 
5
+ let(:account_json) { File.read(File.join(File.dirname(__FILE__),"fixtures/account.json")) }
6
+ let(:accounts_index_json) { File.read(File.join(File.dirname(__FILE__),"fixtures/accounts_index.json")) }
7
+
5
8
  before(:all) do
6
9
  Contactually.configure { |c| c.api_key = 'VALID_API_KEY' }
7
10
  @master = Contactually::API.new
@@ -26,8 +29,7 @@ describe Contactually::Accounts do
26
29
  end
27
30
 
28
31
  it 'returns accounts from json response' do
29
- json = File.read(File.join(File.dirname(__FILE__),"fixtures/accounts_index.json"))
30
- allow(@master).to receive(:call).with('accounts.json', :get, {}).and_return(JSON.load(json))
32
+ allow(@master).to receive(:call).with('accounts.json', :get, {}).and_return(JSON.load(accounts_index_json))
31
33
  expect(subject.index({})).to be_kind_of Array
32
34
  expect(subject.index({})[0]).to be_kind_of Contactually::Account
33
35
  end
@@ -41,8 +43,7 @@ describe Contactually::Accounts do
41
43
  end
42
44
 
43
45
  it 'returns an account' do
44
- json = File.read(File.join(File.dirname(__FILE__),"fixtures/account.json"))
45
- allow(@master).to receive(:call).with('accounts/1.json', :get, { foo: :bar }).and_return(JSON.load(json))
46
+ allow(@master).to receive(:call).with('accounts/1.json', :get, { foo: :bar }).and_return(JSON.load(account_json))
46
47
  expect(subject.show(1, { foo: :bar })).to be_kind_of Contactually::Account
47
48
  end
48
49
  end
data/spec/api_spec.rb CHANGED
@@ -50,15 +50,27 @@ describe Contactually::API do
50
50
  end
51
51
  end
52
52
 
53
+ describe '#accounts' do
54
+ specify do
55
+ expect(subject.accounts).to be_kind_of Contactually::Accounts
56
+ end
57
+ end
58
+
59
+ describe '#contact_groupings' do
60
+ specify do
61
+ expect(subject.contact_groupings).to be_kind_of Contactually::ContactGroupings
62
+ end
63
+ end
64
+
53
65
  describe '#contacts' do
54
66
  specify do
55
67
  expect(subject.contacts).to be_kind_of Contactually::Contacts
56
68
  end
57
69
  end
58
70
 
59
- describe '#notes' do
71
+ describe '#contents' do
60
72
  specify do
61
- expect(subject.notes).to be_kind_of Contactually::Notes
73
+ expect(subject.contents).to be_kind_of Contactually::Contents
62
74
  end
63
75
  end
64
76
 
@@ -68,6 +80,24 @@ describe Contactually::API do
68
80
  end
69
81
  end
70
82
 
83
+ describe '#notes' do
84
+ specify do
85
+ expect(subject.notes).to be_kind_of Contactually::Notes
86
+ end
87
+ end
88
+
89
+ describe '#tasks' do
90
+ specify do
91
+ expect(subject.tasks).to be_kind_of Contactually::Tasks
92
+ end
93
+ end
94
+
95
+ describe 'endpoints' do
96
+ %w{ accounts contact_groupings contacts contents groupings notes tasks }.each do |endpoint|
97
+ specify { expect(subject.respond_to?(endpoint)).to eq true }
98
+ end
99
+ end
100
+
71
101
  describe '#get' do
72
102
  it 'parses from json response' do
73
103
  allow(subject.connection).to receive(:get).
@@ -2,6 +2,8 @@ require 'spec_helper'
2
2
 
3
3
  describe Contactually::ContactGroupings do
4
4
 
5
+ let(:grouping_json) { File.read(File.join(File.dirname(__FILE__),"fixtures/grouping.json")) }
6
+
5
7
  before(:all) do
6
8
  Contactually.configure { |c| c.api_key = 'VALID_API_KEY' }
7
9
  @master = Contactually::API.new
@@ -27,8 +29,7 @@ describe Contactually::ContactGroupings do
27
29
  end
28
30
 
29
31
  it 'returns grouping from json response' do
30
- json = File.read(File.join(File.dirname(__FILE__),"fixtures/grouping.json"))
31
- allow(@master).to receive(:call).with('contacts/1/groupings.json', :post, { grouping_id: 512 }).and_return(JSON.load(json))
32
+ allow(@master).to receive(:call).with('contacts/1/groupings.json', :post, { grouping_id: 512 }).and_return(JSON.load(grouping_json))
32
33
  expect(subject.create(1, { grouping_id: 512 })).to be_kind_of Contactually::Grouping
33
34
  end
34
35
  end
@@ -2,6 +2,9 @@ require 'spec_helper'
2
2
 
3
3
  describe Contactually::Contacts do
4
4
 
5
+ let(:contact_json) { File.read(File.join(File.dirname(__FILE__),"fixtures/contact.json")) }
6
+ let(:contacts_index_json) { File.read(File.join(File.dirname(__FILE__),"fixtures/contacts_index.json")) }
7
+
5
8
  before(:all) do
6
9
  Contactually.configure { |c| c.api_key = 'VALID_API_KEY' }
7
10
  @master = Contactually::API.new
@@ -20,15 +23,13 @@ describe Contactually::Contacts do
20
23
 
21
24
  describe '#create' do
22
25
  it 'calls the api with correct params' do
23
- json = File.read(File.join(File.dirname(__FILE__),"fixtures/contact.json"))
24
- allow(@master).to receive(:call).with('contacts.json', :post, { contact: { foo: :bar }}).and_return(JSON.load(json))
26
+ allow(@master).to receive(:call).with('contacts.json', :post, { contact: { foo: :bar }}).and_return(JSON.load(contact_json))
25
27
  subject.create({ contact: { foo: :bar }})
26
28
  expect(@master).to have_received(:call)
27
29
  end
28
30
 
29
31
  it 'returns a contact' do
30
- json = File.read(File.join(File.dirname(__FILE__),"fixtures/contact.json"))
31
- allow(@master).to receive(:call).with('contacts.json', :post, { contact: { foo: :bar }}).and_return(JSON.load(json))
32
+ allow(@master).to receive(:call).with('contacts.json', :post, { contact: { foo: :bar }}).and_return(JSON.load(contact_json))
32
33
  expect(subject.create({ contact: { foo: :bar } })).to be_kind_of Contactually::Contact
33
34
  end
34
35
  end
@@ -57,8 +58,7 @@ describe Contactually::Contacts do
57
58
  end
58
59
 
59
60
  it 'returns a contact' do
60
- json = File.read(File.join(File.dirname(__FILE__),"fixtures/contact.json"))
61
- allow(@master).to receive(:call).with('contacts/1.json', :get, { foo: :bar }).and_return(JSON.load(json))
61
+ allow(@master).to receive(:call).with('contacts/1.json', :get, { foo: :bar }).and_return(JSON.load(contact_json))
62
62
  expect(subject.show(1, { foo: :bar })).to be_kind_of Contactually::Contact
63
63
  end
64
64
  end
@@ -93,8 +93,7 @@ describe Contactually::Contacts do
93
93
  end
94
94
 
95
95
  it 'returns contacts from json response' do
96
- json = File.read(File.join(File.dirname(__FILE__),"fixtures/contacts_index.json"))
97
- allow(@master).to receive(:call).with('contacts.json', :get, {}).and_return(JSON.load(json))
96
+ allow(@master).to receive(:call).with('contacts.json', :get, {}).and_return(JSON.load(contacts_index_json))
98
97
  expect(subject.index({})).to be_kind_of Array
99
98
  expect(subject.index({})[0]).to be_kind_of Contactually::Contact
100
99
  end
@@ -108,8 +107,7 @@ describe Contactually::Contacts do
108
107
  end
109
108
 
110
109
  it 'returns contacts from json response' do
111
- json = File.read(File.join(File.dirname(__FILE__),"fixtures/contacts_index.json"))
112
- allow(@master).to receive(:call).with('contacts/search.json', :get, { term: :foo_bar }).and_return(JSON.load(json))
110
+ allow(@master).to receive(:call).with('contacts/search.json', :get, { term: :foo_bar }).and_return(JSON.load(contacts_index_json))
113
111
  expect(subject.search({ term: :foo_bar })).to be_kind_of Array
114
112
  expect(subject.search({ term: :foo_bar })[0]).to be_kind_of Contactually::Contact
115
113
  end
@@ -2,6 +2,9 @@ require 'spec_helper'
2
2
 
3
3
  describe Contactually::Contents do
4
4
 
5
+ let(:content_json) { File.read(File.join(File.dirname(__FILE__),"fixtures/content.json")) }
6
+ let(:contents_index_json) { File.read(File.join(File.dirname(__FILE__),"fixtures/contents_index.json")) }
7
+
5
8
  before(:all) do
6
9
  Contactually.configure { |c| c.api_key = 'VALID_API_KEY' }
7
10
  @master = Contactually::API.new
@@ -20,15 +23,13 @@ describe Contactually::Contents do
20
23
 
21
24
  describe '#create' do
22
25
  it 'calls the api with correct params' do
23
- json = File.read(File.join(File.dirname(__FILE__),"fixtures/content.json"))
24
- allow(@master).to receive(:call).with('contents.json', :post, { content: { foo: :bar }}).and_return(JSON.load(json))
26
+ allow(@master).to receive(:call).with('contents.json', :post, { content: { foo: :bar }}).and_return(JSON.load(content_json))
25
27
  subject.create({ content: { foo: :bar }})
26
28
  expect(@master).to have_received(:call)
27
29
  end
28
30
 
29
31
  it 'returns a content' do
30
- json = File.read(File.join(File.dirname(__FILE__),"fixtures/content.json"))
31
- allow(@master).to receive(:call).with('contents.json', :post, { content: { foo: :bar }}).and_return(JSON.load(json))
32
+ allow(@master).to receive(:call).with('contents.json', :post, { content: { foo: :bar }}).and_return(JSON.load(content_json))
32
33
  expect(subject.create({ content: { foo: :bar }})).to be_kind_of Contactually::Content
33
34
  end
34
35
  end
@@ -41,8 +42,7 @@ describe Contactually::Contents do
41
42
  end
42
43
 
43
44
  it 'returns contents from json response' do
44
- json = File.read(File.join(File.dirname(__FILE__),"fixtures/contents_index.json"))
45
- allow(@master).to receive(:call).with('contents.json', :get, {}).and_return(JSON.load(json))
45
+ allow(@master).to receive(:call).with('contents.json', :get, {}).and_return(JSON.load(contents_index_json))
46
46
  expect(subject.index({})).to be_kind_of Array
47
47
  expect(subject.index({})[0]).to be_kind_of Contactually::Content
48
48
  end
@@ -64,8 +64,7 @@ describe Contactually::Contents do
64
64
  end
65
65
 
66
66
  it 'returns a contact' do
67
- json = File.read(File.join(File.dirname(__FILE__),"fixtures/content.json"))
68
- allow(@master).to receive(:call).with('contents/1.json', :get, { foo: :bar }).and_return(JSON.load(json))
67
+ allow(@master).to receive(:call).with('contents/1.json', :get, { foo: :bar }).and_return(JSON.load(content_json))
69
68
  expect(subject.show(1, { foo: :bar })).to be_kind_of Contactually::Content
70
69
  end
71
70
  end
@@ -0,0 +1,24 @@
1
+ require 'spec_helper'
2
+
3
+ describe Contactually::Middleware::ErrorDetector do
4
+
5
+ describe '#cast_error' do
6
+
7
+ it 'detects invalid parameter errors' do
8
+ body = { error: 'Invalid parameters' }.to_json
9
+ expect{ subject.send(:cast_error, body) }.to raise_error Contactually::InvalidParametersError
10
+ end
11
+
12
+ it 'detects duplication errors' do
13
+ body = { error: 'We already have' }.to_json
14
+ expect{ subject.send(:cast_error, body) }.to raise_error Contactually::DuplicatedContactError
15
+ end
16
+
17
+ it 'rescues json parse errors' do
18
+ body = ";foobar;"
19
+ expect{ subject.send(:cast_error, body) }.to raise_error Contactually::APIError
20
+ end
21
+
22
+ end
23
+
24
+ end
@@ -2,6 +2,10 @@ require 'spec_helper'
2
2
 
3
3
  describe Contactually::Groupings do
4
4
 
5
+ let(:groupings_index_json) { File.read(File.join(File.dirname(__FILE__),"fixtures/groupings_index.json")) }
6
+ let(:grouping_json) { File.read(File.join(File.dirname(__FILE__),"fixtures/grouping.json")) }
7
+ let(:groupings_statistics_json) { File.read(File.join(File.dirname(__FILE__), "fixtures/groupings_statistics.json")) }
8
+
5
9
  before(:all) do
6
10
  Contactually.configure { |c| c.api_key = 'VALID_API_KEY' }
7
11
  @master = Contactually::API.new
@@ -27,8 +31,7 @@ describe Contactually::Groupings do
27
31
  end
28
32
 
29
33
  it 'returns groupings from json response' do
30
- json = File.read(File.join(File.dirname(__FILE__),"fixtures/groupings_index.json"))
31
- allow(@master).to receive(:call).with('groupings.json', :get, {}).and_return(JSON.load(json))
34
+ allow(@master).to receive(:call).with('groupings.json', :get, {}).and_return(JSON.load(groupings_index_json))
32
35
  expect(subject.index({})).to be_kind_of Array
33
36
  expect(subject.index({})[0]).to be_kind_of Contactually::Grouping
34
37
  end
@@ -42,8 +45,7 @@ describe Contactually::Groupings do
42
45
  end
43
46
 
44
47
  it 'returns groupings from json response' do
45
- json = File.read(File.join(File.dirname(__FILE__),"fixtures/grouping.json"))
46
- allow(@master).to receive(:call).with('groupings.json', :post, { grouping: { foo: :bar }}).and_return(JSON.load(json))
48
+ allow(@master).to receive(:call).with('groupings.json', :post, { grouping: { foo: :bar }}).and_return(JSON.load(grouping_json))
47
49
  expect(subject.create({ grouping: { foo: :bar }})).to be_kind_of Contactually::Grouping
48
50
  end
49
51
  end
@@ -64,8 +66,7 @@ describe Contactually::Groupings do
64
66
  end
65
67
 
66
68
  it 'returns a grouping from json response' do
67
- json = File.read(File.join(File.dirname(__FILE__),"fixtures/grouping.json"))
68
- allow(@master).to receive(:call).with('groupings/1.json', :get, { foo: :bar }).and_return(JSON.load(json))
69
+ allow(@master).to receive(:call).with('groupings/1.json', :get, { foo: :bar }).and_return(JSON.load(grouping_json))
69
70
  expect(subject.show(1, { foo: :bar })).to be_kind_of Contactually::Grouping
70
71
  end
71
72
  end
@@ -78,8 +79,7 @@ describe Contactually::Groupings do
78
79
  end
79
80
 
80
81
  it 'returns a grouping from json response' do
81
- json = File.read(File.join(File.dirname(__FILE__),"fixtures/grouping.json"))
82
- allow(@master).to receive(:call).with('groupings/1.json', :put, { grouping: { foo: :bar }}).and_return(JSON.load(json))
82
+ allow(@master).to receive(:call).with('groupings/1.json', :put, { grouping: { foo: :bar }}).and_return(JSON.load(grouping_json))
83
83
  expect(subject.update(1, { grouping: { foo: :bar }})).to be_kind_of Contactually::Grouping
84
84
  end
85
85
  end
@@ -92,8 +92,7 @@ describe Contactually::Groupings do
92
92
  end
93
93
 
94
94
  it 'returns statistics object' do
95
- json = File.read(File.join(File.dirname(__FILE__), "fixtures/groupings_statistics.json"))
96
- allow(@master).to receive(:call).with('groupings/1/statistics.json', :get, { foo: :bar }).and_return(JSON.load(json))
95
+ allow(@master).to receive(:call).with('groupings/1/statistics.json', :get, { foo: :bar }).and_return(JSON.load(groupings_statistics_json))
97
96
  expect(subject.statistics(1, { foo: :bar })).to be_kind_of Contactually::GroupingStatistic
98
97
  end
99
98
  end
data/spec/notes_spec.rb CHANGED
@@ -2,6 +2,9 @@ require 'spec_helper'
2
2
 
3
3
  describe Contactually::Notes do
4
4
 
5
+ let(:notes_index_json) { File.read(File.join(File.dirname(__FILE__),"fixtures/notes_index.json")) }
6
+ let(:note_json) { File.read(File.join(File.dirname(__FILE__),"fixtures/note.json")) }
7
+
5
8
  before(:all) do
6
9
  Contactually.configure { |c| c.api_key = 'VALID_API_KEY' }
7
10
  @master = Contactually::API.new
@@ -27,8 +30,7 @@ describe Contactually::Notes do
27
30
  end
28
31
 
29
32
  it 'returns notes from json response' do
30
- json = File.read(File.join(File.dirname(__FILE__),"fixtures/notes_index.json"))
31
- allow(@master).to receive(:call).with('notes.json', :get, {}).and_return(JSON.load(json))
33
+ allow(@master).to receive(:call).with('notes.json', :get, {}).and_return(JSON.load(notes_index_json))
32
34
  expect(subject.index({})).to be_kind_of Array
33
35
  expect(subject.index({})[0]).to be_kind_of Contactually::Note
34
36
  end
@@ -36,45 +38,39 @@ describe Contactually::Notes do
36
38
 
37
39
  describe '#show' do
38
40
  it 'calls the api with correct params' do
39
- json = File.read(File.join(File.dirname(__FILE__),"fixtures/note.json"))
40
- allow(@master).to receive(:call).with('notes/1.json', :get, { foo: :bar }).and_return(JSON.load(json))
41
+ allow(@master).to receive(:call).with('notes/1.json', :get, { foo: :bar }).and_return(JSON.load(note_json))
41
42
  subject.show(1, { foo: :bar })
42
43
  expect(@master).to have_received(:call)
43
44
  end
44
45
 
45
46
  it 'returns a note' do
46
- json = File.read(File.join(File.dirname(__FILE__),"fixtures/note.json"))
47
- allow(@master).to receive(:call).with('notes/1.json', :get, { foo: :bar }).and_return(JSON.load(json))
47
+ allow(@master).to receive(:call).with('notes/1.json', :get, { foo: :bar }).and_return(JSON.load(note_json))
48
48
  expect(subject.show(1, { foo: :bar })).to be_kind_of Contactually::Note
49
49
  end
50
50
  end
51
51
 
52
52
  describe '#create' do
53
53
  it 'calls the api with correct params' do
54
- json = File.read(File.join(File.dirname(__FILE__),"fixtures/note.json"))
55
- allow(@master).to receive(:call).with('notes.json', :post, { note: { foo: :bar }}).and_return(JSON.load(json))
54
+ allow(@master).to receive(:call).with('notes.json', :post, { note: { foo: :bar }}).and_return(JSON.load(note_json))
56
55
  subject.create({ note: { foo: :bar }})
57
56
  expect(@master).to have_received(:call)
58
57
  end
59
58
 
60
59
  it 'returns a note' do
61
- json = File.read(File.join(File.dirname(__FILE__),"fixtures/note.json"))
62
- allow(@master).to receive(:call).with('notes.json', :post, { note: { foo: :bar }}).and_return(JSON.load(json))
60
+ allow(@master).to receive(:call).with('notes.json', :post, { note: { foo: :bar }}).and_return(JSON.load(note_json))
63
61
  expect(subject.create({ note: { foo: :bar }})).to be_kind_of Contactually::Note
64
62
  end
65
63
  end
66
64
 
67
65
  describe '#update' do
68
66
  it 'calls the api with correct params' do
69
- json = File.read(File.join(File.dirname(__FILE__),"fixtures/note.json"))
70
- allow(@master).to receive(:call).with('notes/1.json', :put, { note: { foo: :bar }}).and_return(JSON.load(json))
67
+ allow(@master).to receive(:call).with('notes/1.json', :put, { note: { foo: :bar }}).and_return(JSON.load(note_json))
71
68
  subject.update(1, { note: { foo: :bar }})
72
69
  expect(@master).to have_received(:call)
73
70
  end
74
71
 
75
72
  it 'returns a note' do
76
- json = File.read(File.join(File.dirname(__FILE__),"fixtures/note.json"))
77
- allow(@master).to receive(:call).with('notes/1.json', :put, { note: { foo: :bar }}).and_return(JSON.load(json))
73
+ allow(@master).to receive(:call).with('notes/1.json', :put, { note: { foo: :bar }}).and_return(JSON.load(note_json))
78
74
  expect(subject.update(1, { note: { foo: :bar }})).to be_kind_of Contactually::Note
79
75
  end
80
76
  end
data/spec/tasks_spec.rb CHANGED
@@ -2,6 +2,9 @@ require 'spec_helper'
2
2
 
3
3
  describe Contactually::Tasks do
4
4
 
5
+ let(:task_json) { File.read(File.join(File.dirname(__FILE__),"fixtures/task.json")) }
6
+ let(:tasks_index_json) { File.read(File.join(File.dirname(__FILE__),"fixtures/tasks_index.json")) }
7
+
5
8
  before(:all) do
6
9
  Contactually.configure { |c| c.api_key = 'VALID_API_KEY' }
7
10
  @master = Contactually::API.new
@@ -20,60 +23,52 @@ describe Contactually::Tasks do
20
23
 
21
24
  describe '#show' do
22
25
  it 'calls the api with correct params' do
23
- json = File.read(File.join(File.dirname(__FILE__),"fixtures/task.json"))
24
- allow(@master).to receive(:call).with('tasks/1.json', :get, { foo: :bar }).and_return(JSON.load(json))
26
+ allow(@master).to receive(:call).with('tasks/1.json', :get, { foo: :bar }).and_return(JSON.load(task_json))
25
27
  subject.show(1, { foo: :bar })
26
28
  expect(@master).to have_received(:call)
27
29
  end
28
30
 
29
31
  it 'returns a task' do
30
- json = File.read(File.join(File.dirname(__FILE__),"fixtures/task.json"))
31
- allow(@master).to receive(:call).with('tasks/1.json', :get, { foo: :bar }).and_return(JSON.load(json))
32
+ allow(@master).to receive(:call).with('tasks/1.json', :get, { foo: :bar }).and_return(JSON.load(task_json))
32
33
  expect(subject.show(1, { foo: :bar })).to be_kind_of Contactually::Task
33
34
  end
34
35
  end
35
36
 
36
37
  describe '#complete' do
37
38
  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))
39
+ allow(@master).to receive(:call).with('tasks/1/complete.json', :post, { foo: :bar }).and_return(JSON.load(task_json))
40
40
  subject.complete(1, { foo: :bar })
41
41
  expect(@master).to have_received(:call)
42
42
  end
43
43
 
44
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))
45
+ allow(@master).to receive(:call).with('tasks/1/complete.json', :post, { foo: :bar }).and_return(JSON.load(task_json))
47
46
  expect(subject.complete(1, { foo: :bar })).to be_kind_of Contactually::Task
48
47
  end
49
48
  end
50
49
 
51
50
  describe '#create' do
52
51
  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))
52
+ allow(@master).to receive(:call).with('tasks.json', :post, { foo: :bar }).and_return(JSON.load(task_json))
55
53
  subject.create({ foo: :bar })
56
54
  expect(@master).to have_received(:call)
57
55
  end
58
56
 
59
57
  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))
58
+ allow(@master).to receive(:call).with('tasks.json', :post, { foo: :bar }).and_return(JSON.load(task_json))
62
59
  expect(subject.create({ foo: :bar })).to be_kind_of Contactually::Task
63
60
  end
64
61
  end
65
62
 
66
63
  describe '#update' do
67
64
  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))
65
+ allow(@master).to receive(:call).with('tasks/1.json', :put, { foo: :bar }).and_return(JSON.load(task_json))
70
66
  subject.update(1, { foo: :bar })
71
67
  expect(@master).to have_received(:call)
72
68
  end
73
69
 
74
70
  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))
71
+ allow(@master).to receive(:call).with('tasks/1.json', :put, { foo: :bar }).and_return(JSON.load(task_json))
77
72
  expect(subject.update(1, { foo: :bar })).to be_kind_of Contactually::Task
78
73
  end
79
74
  end
@@ -104,15 +99,13 @@ describe Contactually::Tasks do
104
99
 
105
100
  describe '#ignore' do
106
101
  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))
102
+ allow(@master).to receive(:call).with('tasks/1/ignore.json', :post, { foo: :bar }).and_return(JSON.load(task_json))
109
103
  subject.ignore(1, { foo: :bar })
110
104
  expect(@master).to have_received(:call)
111
105
  end
112
106
 
113
107
  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))
108
+ allow(@master).to receive(:call).with('tasks/1/ignore.json', :post, { foo: :bar }).and_return(JSON.load(task_json))
116
109
  expect(subject.ignore(1, { foo: :bar })).to be_kind_of Contactually::Task
117
110
  end
118
111
  end
@@ -125,8 +118,7 @@ describe Contactually::Tasks do
125
118
  end
126
119
 
127
120
  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))
121
+ allow(@master).to receive(:call).with('tasks.json', :get, {}).and_return(JSON.load(tasks_index_json))
130
122
  expect(subject.index({})).to be_kind_of Array
131
123
  expect(subject.index({})[0]).to be_kind_of Contactually::Task
132
124
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: contactually-api
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
4
+ version: 0.0.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Johannes Heck
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-09-17 00:00:00.000000000 Z
11
+ date: 2014-11-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -129,6 +129,7 @@ files:
129
129
  - spec/contact_groupings_spec.rb
130
130
  - spec/contacts_spec.rb
131
131
  - spec/contents_spec.rb
132
+ - spec/error_detector_spec.rb
132
133
  - spec/fixtures/account.json
133
134
  - spec/fixtures/accounts_index.json
134
135
  - spec/fixtures/contact.json
@@ -177,6 +178,7 @@ test_files:
177
178
  - spec/contact_groupings_spec.rb
178
179
  - spec/contacts_spec.rb
179
180
  - spec/contents_spec.rb
181
+ - spec/error_detector_spec.rb
180
182
  - spec/fixtures/account.json
181
183
  - spec/fixtures/accounts_index.json
182
184
  - spec/fixtures/contact.json