contextio 1.6.0 → 1.7.0

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: f3726a18eda9fc6ebe4ca26a055cefc0ab8c21c6
4
- data.tar.gz: 70f0f22c3c52460d4e81648f2839c05e5f88514f
3
+ metadata.gz: 36032da14317097955708cdfde089a2fb5a97268
4
+ data.tar.gz: 1e0523dcdeddf86c38e925e82091bfc2f83c0d23
5
5
  SHA512:
6
- metadata.gz: 2651ef5e3d6ea6276eaaebf33761120b9e68b42be0a35e8a2cdbe5d8b04481bd1dd55b857b65ec265f601c48c07d3004b4d66e346401553b0b202c22fc57cee5
7
- data.tar.gz: 6258631b9b65b5b624fbb545d8175b768997f84b10268fa05bc31617b2bba921f486934ae469bdb537874f273d27069a79a01c169379a403e1218671b894c0fa
6
+ metadata.gz: 4d6dae4942bbc159c1fcd1ca5237f3e59326abf46cefc283ae99133f7ab116e62f643e7aa595e9fa3c538c23cba34d6dff1e990805546c26f28bedb6fa720da1
7
+ data.tar.gz: 5f0efc5d25d4d4f1133ea372c8a5e9ac28183f74b8e2db2ebf2d510223247efe2fcbce691c47f750d47dc10adb6c106154c502c14879edfb0eabab518b7d7d4b
data/CHANGES.md CHANGED
@@ -1,5 +1,14 @@
1
1
  # Changes
2
2
 
3
+ ## 1.7.0
4
+
5
+ * Further README updates for clarity. - Johnny Goodman
6
+ * Convert to Faraday back-end for making requests. - Ben Hamill
7
+ * Fix bug in `ContextIO::Source` that caused the `sync_data` method to always
8
+ fail. - Dominik Gehl
9
+ * Improve documentation for `ContextIO::API::ResourceCollection#where` to
10
+ include a link to the general API documentation. - Chris McNair
11
+
3
12
  ## 1.6.0
4
13
 
5
14
  * Add `version` and `base_url` instance variables to API. - Dominik Gehl
data/README.md CHANGED
@@ -184,7 +184,8 @@ Pass dates in to message queries as Unix Epoch integers.
184
184
  require 'active_support/all'
185
185
 
186
186
  account.messages.where(date_before: 3.hours.ago.to_i, date_after: 5.hours.ago.to_i).each do |message|
187
- puts "(#{message.date}) #{message.subject}"
187
+ puts message.subject #=> "The subject of my email"
188
+ puts message.received_at #=> 2013-07-31 20:33:56 -0500
188
189
  end
189
190
  ```
190
191
 
@@ -299,12 +300,12 @@ message = account.messages[message_id]
299
300
  message.files.class #=> ContextIO::FileCollection
300
301
  message.files.count #=> 2
301
302
  message.files.map { |f| f.file_name } #=> ["at_icon.png", "argyle_slides.png"]
302
- message.files.first.resource_url #=> https://contextio_to_s3_redirect_url.io
303
+ message.files.first.content_link #=> https://contextio_to_s3_redirect_url
303
304
  ```
304
305
 
305
- The file['resource_url'] url is a S3 backed temporary link. It is intended
306
- to be used promptly after being called. Do not store off this link. Instead,
307
- store off the message_id and request on demand.
306
+ The file['content_link'] url is a S3 backed temporary link. It is intended to be
307
+ used promptly after being called. Do not store off this link. Instead, store off
308
+ the message_id and request on demand.
308
309
 
309
310
 
310
311
  ### On Laziness
data/Rakefile CHANGED
@@ -19,6 +19,7 @@ rescue Bundler::BundlerError => e
19
19
  end
20
20
 
21
21
  require 'rake'
22
+ require 'bundler/gem_tasks'
22
23
 
23
24
  require 'rspec/core/rake_task'
24
25
  RSpec::Core::RakeTask.new
data/contextio.gemspec CHANGED
@@ -17,7 +17,9 @@ Gem::Specification.new do |gem|
17
17
  gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
18
18
  gem.require_paths = ['lib']
19
19
 
20
- gem.add_dependency 'oauth', '~> 0.4.5'
20
+ gem.add_dependency 'faraday', '~> 0.8.0'
21
+ gem.add_dependency 'faraday_middleware', '~> 0.9.0'
22
+ gem.add_dependency 'simple_oauth', '~> 0.2.0'
21
23
 
22
24
  gem.add_development_dependency 'bundler'
23
25
  gem.add_development_dependency 'rubygems-tasks', '~> 0.2'
@@ -26,5 +28,5 @@ Gem::Specification.new do |gem|
26
28
  gem.add_development_dependency 'yard'
27
29
  gem.add_development_dependency 'redcarpet'
28
30
  gem.add_development_dependency 'pry-doc'
29
- gem.add_development_dependency 'fakeweb'
31
+ gem.add_development_dependency 'webmock'
30
32
  end
@@ -70,7 +70,8 @@ class ContextIO
70
70
  end
71
71
 
72
72
  # Specify one or more constraints for limiting resources in this
73
- # collection. See individual classes for the list of valid constraints.
73
+ # collection. See individual classes in the
74
+ # [Context.IO docs](http://context.io/docs/2.0/) for the list of valid constraints.
74
75
  # Not all collections have valid where constraints at all.
75
76
  #
76
77
  # This can be chained at need and doesn't actually cause the API to get
data/lib/contextio/api.rb CHANGED
@@ -1,6 +1,7 @@
1
1
  require 'uri'
2
- require 'oauth'
3
2
  require 'json'
3
+ require 'faraday'
4
+ require 'faraday_middleware'
4
5
 
5
6
  require 'contextio/api/url_builder'
6
7
 
@@ -93,15 +94,15 @@ class ContextIO
93
94
  #
94
95
  # @raise [API::Error] if the response code isn't in the 200 or 300 range.
95
96
  def request(method, resource_path, params = {})
96
- response = oauth_request(method, resource_path, params)
97
+ response = oauth_request(method, resource_path, params, { 'Accept' => 'application/json' })
97
98
  body = response.body
98
- results = JSON.parse(body) unless response.body.empty?
99
+ results = JSON.parse(body.to_s) unless response.body.to_s.empty?
99
100
 
100
- if response.code =~ /[45]\d\d/
101
+ unless response.success?
101
102
  if results.is_a?(Hash) && results['type'] == 'error'
102
103
  message = results['value']
103
104
  else
104
- message = response.message
105
+ message = "HTTP #{response.status} Error"
105
106
  end
106
107
 
107
108
  raise API::Error, message
@@ -111,10 +112,10 @@ class ContextIO
111
112
  end
112
113
 
113
114
  def raw_request(method, resource_path, params={})
114
- response = oauth_request(method, resource_path, params, 'User-Agent' => user_agent_string)
115
+ response = oauth_request(method, resource_path, params)
115
116
 
116
- if response.code =~ /[45]\d\d/
117
- raise API::Error, response.message
117
+ unless response.success?
118
+ raise API::Error, "HTTP #{response.status} Error"
118
119
  end
119
120
 
120
121
  response.body
@@ -129,24 +130,18 @@ class ContextIO
129
130
  # @param [{String, Symbol => String, Symbol, Array<String, Symbol>}] params
130
131
  # A Hash of the query parameters for the action represented by this
131
132
  # request.
133
+ # @param [{String, Symbol => String, Symbol, Array<String, Symbol>}] headers
134
+ # A Hash of headers to be merged with the default headers for making
135
+ # requests.
132
136
  #
133
- # @return [Net::HTTP*] The response object from the request.
137
+ # @return [Faraday::Response] The response object from the request.
134
138
  def oauth_request(method, resource_path, params, headers=nil)
135
- headers ||= { 'Accept' => 'application/json', 'User-Agent' => user_agent_string }
136
139
  normalized_params = params.inject({}) do |normalized_params, (key, value)|
137
140
  normalized_params[key.to_sym] = value
138
141
  normalized_params
139
142
  end
140
143
 
141
- # The below array used to include put, too, but there is a weirdness in
142
- # the oauth gem with PUT and signing requests. See
143
- # https://github.com/oauth/oauth-ruby/pull/34#issuecomment-5862199 for
144
- # some discussion on the matter. This is a work-around.
145
- if %w(post).include? method.to_s.downcase
146
- token.request(method, path(resource_path), normalized_params, headers)
147
- else # GET, DELETE, HEAD, etc.
148
- token.request(method, path(resource_path, normalized_params), nil, headers)
149
- end
144
+ connection.send(method, path(resource_path), normalized_params, headers)
150
145
  end
151
146
 
152
147
  # So that we can accept full URLs, this strips the domain and version number
@@ -179,18 +174,17 @@ class ContextIO
179
174
  "?#{URI.encode_www_form(params)}"
180
175
  end
181
176
 
182
- # @!attribute [r] consumer
183
- # @return [OAuth::Consumer] An Oauth consumer object for credentials
184
- # purposes.
185
- def consumer
186
- @consumer ||= OAuth::Consumer.new(key, secret, @opts.merge(site: base_url))
187
- end
177
+ # @!attribute [r] connection
178
+ # @return [Faraday::Connection] A handle on the Faraday connection object.
179
+ def connection
180
+ @connection ||= Faraday::Connection.new(base_url) do |faraday|
181
+ faraday.headers['User-Agent'] = user_agent_string
182
+
183
+ faraday.request :oauth, consumer_key: key, consumer_secret: secret
184
+ faraday.request :url_encoded
188
185
 
189
- # @!attribute [r] token
190
- # @return [Oauth::AccessToken] An Oauth token object for credentials
191
- # purposes.
192
- def token
193
- @token ||= OAuth::AccessToken.new(consumer)
186
+ faraday.adapter Faraday.default_adapter
187
+ end
194
188
  end
195
189
  end
196
190
  end
@@ -49,7 +49,7 @@ class ContextIO
49
49
 
50
50
  sync_hashes = api.request(:get, "#{resource_url}/sync")
51
51
 
52
- @sync_data = ContextIO::SourceSyncData.new(sync_hashes)
52
+ @sync_data = ContextIO::SourceSyncData.new(label, sync_hashes)
53
53
 
54
54
  return @sync_data
55
55
  end
@@ -1,6 +1,6 @@
1
1
  class ContextIO
2
2
  # @private
3
- VERSION = "1.6.0"
3
+ VERSION = "1.7.0"
4
4
 
5
5
  # The gem version.
6
6
  #
@@ -0,0 +1,15 @@
1
+ require 'spec_helper'
2
+ require 'contextio'
3
+
4
+ describe "Syncing data for a source" do
5
+ let(:api) { double(:api) }
6
+ subject { ContextIO::Source.new(api, resource_url: 'resource url') }
7
+
8
+ before do
9
+ allow(api).to receive(:request).and_return({foo: 'bar'})
10
+ end
11
+
12
+ it "initializes a SourceSyncData correctly" do
13
+ expect { subject.sync_data }.to_not raise_exception
14
+ end
15
+ end
data/spec/spec_helper.rb CHANGED
@@ -1,6 +1,6 @@
1
1
  require 'rspec'
2
2
  require 'pry'
3
- require 'fakeweb'
3
+ require 'webmock/rspec'
4
4
 
5
5
  RSpec.configure do |rspec|
6
6
  rspec.run_all_when_everything_filtered = true
@@ -18,4 +18,4 @@ RSpec.configure do |rspec|
18
18
  end
19
19
  end
20
20
 
21
- FakeWeb.allow_net_connect = false
21
+ WebMock.disable_net_connect!
@@ -122,9 +122,11 @@ describe ContextIO::API do
122
122
 
123
123
  context "with a good response" do
124
124
  before do
125
- FakeWeb.register_uri(
125
+ WebMock.stub_request(
126
126
  :get,
127
- 'https://api.context.io/2.0/test',
127
+ 'https://api.context.io/2.0/test'
128
+ ).to_return(
129
+ status: 200,
128
130
  body: JSON.dump('a' => 'b', 'c' => 'd')
129
131
  )
130
132
  end
@@ -136,10 +138,11 @@ describe ContextIO::API do
136
138
 
137
139
  context "with a bad response that has a body" do
138
140
  before do
139
- FakeWeb.register_uri(
141
+ WebMock.stub_request(
140
142
  :get,
141
- 'https://api.context.io/2.0/test',
142
- status: ['400', 'Bad Request'],
143
+ 'https://api.context.io/2.0/test'
144
+ ).to_return(
145
+ status: 400,
143
146
  body: JSON.dump('type' => 'error', 'value' => 'nope')
144
147
  )
145
148
  end
@@ -151,15 +154,16 @@ describe ContextIO::API do
151
154
 
152
155
  context "with a bad response that has no body" do
153
156
  before do
154
- FakeWeb.register_uri(
157
+ WebMock.stub_request(
155
158
  :get,
156
- 'https://api.context.io/2.0/test',
157
- status: ['400', 'Bad Request']
159
+ 'https://api.context.io/2.0/test'
160
+ ).to_return(
161
+ status: 400
158
162
  )
159
163
  end
160
164
 
161
165
  it "raises an API error with the header message" do
162
- expect { subject }.to raise_error(ContextIO::API::Error, 'Bad Request')
166
+ expect { subject }.to raise_error(ContextIO::API::Error, 'HTTP 400 Error')
163
167
  end
164
168
  end
165
169
  end
metadata CHANGED
@@ -1,139 +1,167 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: contextio
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.6.0
4
+ version: 1.7.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ben Hamill
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-08-01 00:00:00.000000000 Z
11
+ date: 2014-01-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
- name: oauth
14
+ name: faraday
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - ~>
17
+ - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: 0.4.5
19
+ version: 0.8.0
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: 0.4.5
26
+ version: 0.8.0
27
+ - !ruby/object:Gem::Dependency
28
+ name: faraday_middleware
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: 0.9.0
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: 0.9.0
41
+ - !ruby/object:Gem::Dependency
42
+ name: simple_oauth
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: 0.2.0
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: 0.2.0
27
55
  - !ruby/object:Gem::Dependency
28
56
  name: bundler
29
57
  requirement: !ruby/object:Gem::Requirement
30
58
  requirements:
31
- - - '>='
59
+ - - ">="
32
60
  - !ruby/object:Gem::Version
33
61
  version: '0'
34
62
  type: :development
35
63
  prerelease: false
36
64
  version_requirements: !ruby/object:Gem::Requirement
37
65
  requirements:
38
- - - '>='
66
+ - - ">="
39
67
  - !ruby/object:Gem::Version
40
68
  version: '0'
41
69
  - !ruby/object:Gem::Dependency
42
70
  name: rubygems-tasks
43
71
  requirement: !ruby/object:Gem::Requirement
44
72
  requirements:
45
- - - ~>
73
+ - - "~>"
46
74
  - !ruby/object:Gem::Version
47
75
  version: '0.2'
48
76
  type: :development
49
77
  prerelease: false
50
78
  version_requirements: !ruby/object:Gem::Requirement
51
79
  requirements:
52
- - - ~>
80
+ - - "~>"
53
81
  - !ruby/object:Gem::Version
54
82
  version: '0.2'
55
83
  - !ruby/object:Gem::Dependency
56
84
  name: rspec
57
85
  requirement: !ruby/object:Gem::Requirement
58
86
  requirements:
59
- - - ~>
87
+ - - "~>"
60
88
  - !ruby/object:Gem::Version
61
89
  version: '2.14'
62
90
  type: :development
63
91
  prerelease: false
64
92
  version_requirements: !ruby/object:Gem::Requirement
65
93
  requirements:
66
- - - ~>
94
+ - - "~>"
67
95
  - !ruby/object:Gem::Version
68
96
  version: '2.14'
69
97
  - !ruby/object:Gem::Dependency
70
98
  name: rake
71
99
  requirement: !ruby/object:Gem::Requirement
72
100
  requirements:
73
- - - '>='
101
+ - - ">="
74
102
  - !ruby/object:Gem::Version
75
103
  version: '0'
76
104
  type: :development
77
105
  prerelease: false
78
106
  version_requirements: !ruby/object:Gem::Requirement
79
107
  requirements:
80
- - - '>='
108
+ - - ">="
81
109
  - !ruby/object:Gem::Version
82
110
  version: '0'
83
111
  - !ruby/object:Gem::Dependency
84
112
  name: yard
85
113
  requirement: !ruby/object:Gem::Requirement
86
114
  requirements:
87
- - - '>='
115
+ - - ">="
88
116
  - !ruby/object:Gem::Version
89
117
  version: '0'
90
118
  type: :development
91
119
  prerelease: false
92
120
  version_requirements: !ruby/object:Gem::Requirement
93
121
  requirements:
94
- - - '>='
122
+ - - ">="
95
123
  - !ruby/object:Gem::Version
96
124
  version: '0'
97
125
  - !ruby/object:Gem::Dependency
98
126
  name: redcarpet
99
127
  requirement: !ruby/object:Gem::Requirement
100
128
  requirements:
101
- - - '>='
129
+ - - ">="
102
130
  - !ruby/object:Gem::Version
103
131
  version: '0'
104
132
  type: :development
105
133
  prerelease: false
106
134
  version_requirements: !ruby/object:Gem::Requirement
107
135
  requirements:
108
- - - '>='
136
+ - - ">="
109
137
  - !ruby/object:Gem::Version
110
138
  version: '0'
111
139
  - !ruby/object:Gem::Dependency
112
140
  name: pry-doc
113
141
  requirement: !ruby/object:Gem::Requirement
114
142
  requirements:
115
- - - '>='
143
+ - - ">="
116
144
  - !ruby/object:Gem::Version
117
145
  version: '0'
118
146
  type: :development
119
147
  prerelease: false
120
148
  version_requirements: !ruby/object:Gem::Requirement
121
149
  requirements:
122
- - - '>='
150
+ - - ">="
123
151
  - !ruby/object:Gem::Version
124
152
  version: '0'
125
153
  - !ruby/object:Gem::Dependency
126
- name: fakeweb
154
+ name: webmock
127
155
  requirement: !ruby/object:Gem::Requirement
128
156
  requirements:
129
- - - '>='
157
+ - - ">="
130
158
  - !ruby/object:Gem::Version
131
159
  version: '0'
132
160
  type: :development
133
161
  prerelease: false
134
162
  version_requirements: !ruby/object:Gem::Requirement
135
163
  requirements:
136
- - - '>='
164
+ - - ">="
137
165
  - !ruby/object:Gem::Version
138
166
  version: '0'
139
167
  description: Provides Ruby interface to Context.IO
@@ -143,10 +171,10 @@ executables: []
143
171
  extensions: []
144
172
  extra_rdoc_files: []
145
173
  files:
146
- - .document
147
- - .gitignore
148
- - .rspec
149
- - .yardopts
174
+ - ".document"
175
+ - ".gitignore"
176
+ - ".rspec"
177
+ - ".yardopts"
150
178
  - CHANGES.md
151
179
  - Gemfile
152
180
  - LICENSE.md
@@ -191,6 +219,7 @@ files:
191
219
  - spec/config.yml.example
192
220
  - spec/integration/accounts_messages_spec.rb
193
221
  - spec/integration/folders_messages_spec.rb
222
+ - spec/integration/source_sync_data_spec.rb
194
223
  - spec/spec_helper.rb
195
224
  - spec/unit/contextio/account_collection_spec.rb
196
225
  - spec/unit/contextio/account_spec.rb
@@ -218,17 +247,17 @@ require_paths:
218
247
  - lib
219
248
  required_ruby_version: !ruby/object:Gem::Requirement
220
249
  requirements:
221
- - - '>='
250
+ - - ">="
222
251
  - !ruby/object:Gem::Version
223
252
  version: '0'
224
253
  required_rubygems_version: !ruby/object:Gem::Requirement
225
254
  requirements:
226
- - - '>='
255
+ - - ">="
227
256
  - !ruby/object:Gem::Version
228
257
  version: '0'
229
258
  requirements: []
230
259
  rubyforge_project:
231
- rubygems_version: 2.0.3
260
+ rubygems_version: 2.2.0
232
261
  signing_key:
233
262
  specification_version: 4
234
263
  summary: Provides interface to Context.IO
@@ -236,6 +265,7 @@ test_files:
236
265
  - spec/config.yml.example
237
266
  - spec/integration/accounts_messages_spec.rb
238
267
  - spec/integration/folders_messages_spec.rb
268
+ - spec/integration/source_sync_data_spec.rb
239
269
  - spec/spec_helper.rb
240
270
  - spec/unit/contextio/account_collection_spec.rb
241
271
  - spec/unit/contextio/account_spec.rb