contextio 1.2.3 → 1.2.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.
- data/CHANGES.md +9 -0
- data/README.md +77 -20
- data/lib/contextio/api/resource.rb +10 -2
- data/lib/contextio/api/resource_collection.rb +1 -1
- data/lib/contextio/api.rb +6 -2
- data/lib/contextio/version.rb +1 -1
- data/spec/integration/accounts_messages_spec.rb +12 -0
- data/spec/{contextio → unit/contextio}/account_collection_spec.rb +0 -0
- data/spec/{contextio → unit/contextio}/account_spec.rb +0 -0
- data/spec/{contextio → unit/contextio}/api/association_helpers_spec.rb +0 -0
- data/spec/{contextio → unit/contextio}/api/resource_collection_spec.rb +0 -0
- data/spec/{contextio → unit/contextio}/api/resource_spec.rb +0 -0
- data/spec/{contextio → unit/contextio}/api/url_builder_spec.rb +0 -0
- data/spec/{contextio → unit/contextio}/api_spec.rb +0 -0
- data/spec/{contextio → unit/contextio}/connect_token_collection_spec.rb +0 -0
- data/spec/{contextio → unit/contextio}/connect_token_spec.rb +0 -0
- data/spec/{contextio → unit/contextio}/email_settings_spec.rb +0 -0
- data/spec/{contextio → unit/contextio}/oauth_provider_collection_spec.rb +0 -0
- data/spec/{contextio → unit/contextio}/oauth_provider_spec.rb +0 -0
- data/spec/{contextio → unit/contextio}/source_collection_spec.rb +0 -0
- data/spec/{contextio → unit/contextio}/source_spec.rb +0 -0
- data/spec/{contextio → unit/contextio}/version_spec.rb +0 -0
- data/spec/{contextio_spec.rb → unit/contextio_spec.rb} +0 -0
- metadata +36 -34
data/CHANGES.md
CHANGED
@@ -1,5 +1,14 @@
|
|
1
1
|
# Changes
|
2
2
|
|
3
|
+
## 1.2.4
|
4
|
+
|
5
|
+
* Add link to gem documentation to top of README. - Ben Hamill
|
6
|
+
* Expand README to clarify gem usage. - Ben Hamill
|
7
|
+
* Make `ResourceCollection#[]` correctly pass down the "owning" associated
|
8
|
+
object to instances created with it. - Ben Hamill
|
9
|
+
* Work around the OAuth gem handling PUT request signing a bit oddly. - Ben
|
10
|
+
Hamill
|
11
|
+
|
3
12
|
## 1.2.3
|
4
13
|
|
5
14
|
* Fix infinite loop in ConnectToken URL building. - Ben Hamill
|
data/README.md
CHANGED
@@ -2,24 +2,50 @@
|
|
2
2
|
|
3
3
|
* [Homepage](https://github.com/contextio/contextio-ruby#readme)
|
4
4
|
* [API Documentation](http://context.io/docs/2.0/)
|
5
|
+
* [Gem Documentation](http://rubydoc.info/gems/contextio/frames)
|
5
6
|
* [Sign Up](http://context.io)
|
6
7
|
|
8
|
+
|
7
9
|
## Description
|
8
10
|
|
9
11
|
Provides a Ruby interface to [Context.IO](http://context.io). The general design
|
10
12
|
was inspired by the wonderful [aws-sdk](https://github.com/aws/aws-sdk-ruby)
|
11
13
|
gem. You start with an object that represents your account with Context.IO and
|
12
|
-
then you deal with collections within that going forward
|
14
|
+
then you deal with collections within that going forward (see the [Usage
|
15
|
+
section](#usage)).
|
16
|
+
|
17
|
+
|
18
|
+
## A Note On Method Names
|
19
|
+
|
20
|
+
If you're looking at the [Context.IO docs](http://context.io/docs/2.0/), it is
|
21
|
+
important to note that there are some attributes that've been renamed to be a
|
22
|
+
bit more Ruby-friendly. In general, if the API returns a number meant to be
|
23
|
+
seconds-from-epoch, then it's been converted to return a `Time` (e.g. `updated`
|
24
|
+
has changed to `updated_at`) and a boolean has converted to something with a `?`
|
25
|
+
at the end (e.g. `HasChildren` and `initial_import_finished` are `has_children?`
|
26
|
+
and `initial_import_finished?`, respectively). See the [gem
|
27
|
+
docs](http://rubydoc.info/gems/contextio/frames) for a specific class when in
|
28
|
+
doubt.
|
29
|
+
|
30
|
+
|
31
|
+
## Install
|
32
|
+
|
33
|
+
$ gem install contextio
|
34
|
+
|
35
|
+
Or, of course, put this in your Gemfile:
|
36
|
+
|
37
|
+
gem contextio
|
13
38
|
|
14
|
-
If you're looking at the Context.IO docs, it is important to note that there are
|
15
|
-
some attributes that've been renamed to be a bit more Ruby-friendly. In general,
|
16
|
-
if the API returns a number meant to be seconds-from-epoch, then it's been
|
17
|
-
converted to return a `Time` (e.g. `updated` has changed to `updated_at`) and a
|
18
|
-
boolean has converted to something with a `?` at the end (e.g. `HasChildren` and
|
19
|
-
`initial_import_finished` are `has_children?` and `initial_import_finished?`,
|
20
|
-
respectively).
|
21
39
|
|
22
|
-
##
|
40
|
+
## Version Numbers
|
41
|
+
|
42
|
+
This gem adheres to [SemVer](http://semver.org/). So you should be pretty safe
|
43
|
+
upgrading from 1.0.0 to 1.9.9. Whatever as long as the major version doesn't
|
44
|
+
bump. When the major version bumps, be warned; upgrading will take some kind of
|
45
|
+
effort.
|
46
|
+
|
47
|
+
|
48
|
+
## Usage
|
23
49
|
|
24
50
|
```ruby
|
25
51
|
require 'contextio'
|
@@ -47,23 +73,53 @@ require 'contextio'
|
|
47
73
|
contextio = ContextIO.new('your_api_key', 'your_api_secret')
|
48
74
|
|
49
75
|
account = contextio.accounts[some_account_id]
|
50
|
-
|
76
|
+
message = account.messages[some_message_id]
|
51
77
|
```
|
52
78
|
|
53
|
-
## Install
|
54
79
|
|
55
|
-
|
80
|
+
### On Laziness
|
56
81
|
|
57
|
-
|
82
|
+
This gem is architected to be as lazy as possible. It won't make an HTTP request
|
83
|
+
until you ask it for some data that it knows it needs to fetch. An example might
|
84
|
+
be illustrative:
|
58
85
|
|
59
|
-
|
86
|
+
```ruby
|
87
|
+
require 'contextio'
|
60
88
|
|
61
|
-
|
89
|
+
contextio = ContextIO.new('your_api_key', 'your_api_secret')
|
90
|
+
|
91
|
+
account = contextio.accounts['1234'] # No request made here.
|
92
|
+
account.last_name # Request made here.
|
93
|
+
account.first_name # No request made here.
|
94
|
+
```
|
95
|
+
|
96
|
+
Note that when it made the request, it stored the data it got back, which
|
97
|
+
included the first name, so it didn't need to make a second request. Asking for
|
98
|
+
the value of any attribute listed in the [gem
|
99
|
+
docs](http://rubydoc.info/gems/contextio/frames) will trigger the request.
|
100
|
+
|
101
|
+
|
102
|
+
### On Requests and Methods
|
103
|
+
|
104
|
+
There are some consistent mappings between the requests documented in the [API
|
105
|
+
docs](http://context.io/docs/2.0/) and the methods implemented in the gem.
|
106
|
+
|
107
|
+
**For collections of resources:**
|
108
|
+
|
109
|
+
* the object its self sort of represents the collection-level `GET` (treat it
|
110
|
+
like any other `Enumerable`).
|
111
|
+
* `#where` is how you set up the filters on the collection-level `GET`.
|
112
|
+
* `#create` maps to the collection-level `POST` or `PUT`, as appropriate.
|
113
|
+
* `#[]` maps to the individual-level `GET`, but (as mentioned above) is lazy.
|
114
|
+
|
115
|
+
**For individual resources**
|
116
|
+
|
117
|
+
* the object its self sort of represents the individual-level `GET` (but see
|
118
|
+
`#[]` above).
|
119
|
+
* `#delete` maps to the individual-level `DELETE`.
|
120
|
+
* `#update` maps to the individual-level `POST` (except in a few cases like
|
121
|
+
`Message#copy_to` and `Message#move_to`).
|
62
122
|
|
63
|
-
This gem adheres to [SemVer](http://semver.org/). So you should be pretty safe
|
64
|
-
upgrading from 1.0.0 to 1.9.9. Whatever as long as the major version doesn't
|
65
|
-
bump. When the major version bumps, be warned; upgrading will take some kind of
|
66
|
-
effort.
|
67
123
|
|
68
124
|
## Contributing
|
69
125
|
|
@@ -81,8 +137,9 @@ likely to get in (or get in faster) the closer you stick to these steps:
|
|
81
137
|
If you don't know how to fix something, even just a Pull Request that includes a
|
82
138
|
failing test can be helpful. If in doubt, make an Issue to discuss.
|
83
139
|
|
140
|
+
|
84
141
|
## Copyright
|
85
142
|
|
86
143
|
Copyright (c) 2012 Context.IO
|
87
144
|
|
88
|
-
See LICENSE.md for details.
|
145
|
+
This gem is distributed under the MIT License. See LICENSE.md for details.
|
@@ -190,7 +190,7 @@ class ContextIO
|
|
190
190
|
# resource.
|
191
191
|
def belongs_to(association_name)
|
192
192
|
define_method(association_name) do
|
193
|
-
if
|
193
|
+
if instance_variable_defined?("@#{association_name}")
|
194
194
|
instance_variable_get("@#{association_name}")
|
195
195
|
else
|
196
196
|
association_attrs = api_attributes[association_name.to_s]
|
@@ -219,7 +219,15 @@ class ContextIO
|
|
219
219
|
define_method(association_name) do
|
220
220
|
association_class = ContextIO::API::AssociationHelpers.class_for_association_name(association_name)
|
221
221
|
|
222
|
-
instance_variable_get("@#{association_name}") ||
|
222
|
+
instance_variable_get("@#{association_name}") ||
|
223
|
+
instance_variable_set(
|
224
|
+
"@#{association_name}",
|
225
|
+
association_class.new(
|
226
|
+
api,
|
227
|
+
self.class.association_name => self,
|
228
|
+
attribute_hashes: api_attributes[association_name.to_s]
|
229
|
+
)
|
230
|
+
)
|
223
231
|
end
|
224
232
|
|
225
233
|
associations << association_name.to_sym
|
@@ -103,7 +103,7 @@ class ContextIO
|
|
103
103
|
# @param [String] key The Provider Consumer Key for the
|
104
104
|
# provider you want to interact with.
|
105
105
|
def [](key)
|
106
|
-
resource_class.new(api, resource_class.primary_key => key)
|
106
|
+
resource_class.new(api, associations_hash.merge(resource_class.primary_key => key))
|
107
107
|
end
|
108
108
|
|
109
109
|
private
|
data/lib/contextio/api.rb
CHANGED
@@ -130,10 +130,14 @@ class ContextIO
|
|
130
130
|
def oauth_request(method, resource_path, params, headers=nil)
|
131
131
|
headers ||= { 'Accept' => 'application/json', 'User-Agent' => user_agent_string }
|
132
132
|
|
133
|
-
|
133
|
+
# The below array used to include put, too, but there is a weirdness in
|
134
|
+
# the oauth gem with PUT and signing requests. See
|
135
|
+
# https://github.com/oauth/oauth-ruby/pull/34#issuecomment-5862199 for
|
136
|
+
# some discussion on the matter. This is a work-around.
|
137
|
+
if %w(post).include? method.to_s.downcase
|
134
138
|
token.request(method, path(resource_path), params, headers)
|
135
139
|
else # GET, DELETE, HEAD, etc.
|
136
|
-
token.request(method, path(resource_path, params), headers)
|
140
|
+
token.request(method, path(resource_path, params), nil, headers)
|
137
141
|
end
|
138
142
|
end
|
139
143
|
|
data/lib/contextio/version.rb
CHANGED
@@ -0,0 +1,12 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'contextio'
|
3
|
+
|
4
|
+
describe "A Message created from an Account" do
|
5
|
+
let(:api) { double(:api) }
|
6
|
+
let(:account) { ContextIO::Account.new(api, id: '1234', messages: [{}]) }
|
7
|
+
let(:message) { account.messages['4321'] }
|
8
|
+
|
9
|
+
it "has a handle back to the account" do
|
10
|
+
expect(message.account).to be(account)
|
11
|
+
end
|
12
|
+
end
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: contextio
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.2.
|
4
|
+
version: 1.2.4
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2013-02-
|
12
|
+
date: 2013-02-28 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: oauth
|
@@ -208,23 +208,24 @@ files:
|
|
208
208
|
- lib/contextio/webhook.rb
|
209
209
|
- lib/contextio/webhook_collection.rb
|
210
210
|
- spec/config.yml.example
|
211
|
-
- spec/
|
212
|
-
- spec/contextio/account_spec.rb
|
213
|
-
- spec/contextio/api/association_helpers_spec.rb
|
214
|
-
- spec/contextio/api/resource_collection_spec.rb
|
215
|
-
- spec/contextio/api/resource_spec.rb
|
216
|
-
- spec/contextio/api/url_builder_spec.rb
|
217
|
-
- spec/contextio/api_spec.rb
|
218
|
-
- spec/contextio/connect_token_collection_spec.rb
|
219
|
-
- spec/contextio/connect_token_spec.rb
|
220
|
-
- spec/contextio/email_settings_spec.rb
|
221
|
-
- spec/contextio/oauth_provider_collection_spec.rb
|
222
|
-
- spec/contextio/oauth_provider_spec.rb
|
223
|
-
- spec/contextio/source_collection_spec.rb
|
224
|
-
- spec/contextio/source_spec.rb
|
225
|
-
- spec/contextio/version_spec.rb
|
226
|
-
- spec/contextio_spec.rb
|
211
|
+
- spec/integration/accounts_messages_spec.rb
|
227
212
|
- spec/spec_helper.rb
|
213
|
+
- spec/unit/contextio/account_collection_spec.rb
|
214
|
+
- spec/unit/contextio/account_spec.rb
|
215
|
+
- spec/unit/contextio/api/association_helpers_spec.rb
|
216
|
+
- spec/unit/contextio/api/resource_collection_spec.rb
|
217
|
+
- spec/unit/contextio/api/resource_spec.rb
|
218
|
+
- spec/unit/contextio/api/url_builder_spec.rb
|
219
|
+
- spec/unit/contextio/api_spec.rb
|
220
|
+
- spec/unit/contextio/connect_token_collection_spec.rb
|
221
|
+
- spec/unit/contextio/connect_token_spec.rb
|
222
|
+
- spec/unit/contextio/email_settings_spec.rb
|
223
|
+
- spec/unit/contextio/oauth_provider_collection_spec.rb
|
224
|
+
- spec/unit/contextio/oauth_provider_spec.rb
|
225
|
+
- spec/unit/contextio/source_collection_spec.rb
|
226
|
+
- spec/unit/contextio/source_spec.rb
|
227
|
+
- spec/unit/contextio/version_spec.rb
|
228
|
+
- spec/unit/contextio_spec.rb
|
228
229
|
homepage: https://github.com/contextio/contextio-ruby#readme
|
229
230
|
licenses:
|
230
231
|
- MIT
|
@@ -252,21 +253,22 @@ specification_version: 3
|
|
252
253
|
summary: Provides interface to Context.IO
|
253
254
|
test_files:
|
254
255
|
- spec/config.yml.example
|
255
|
-
- spec/
|
256
|
-
- spec/contextio/account_spec.rb
|
257
|
-
- spec/contextio/api/association_helpers_spec.rb
|
258
|
-
- spec/contextio/api/resource_collection_spec.rb
|
259
|
-
- spec/contextio/api/resource_spec.rb
|
260
|
-
- spec/contextio/api/url_builder_spec.rb
|
261
|
-
- spec/contextio/api_spec.rb
|
262
|
-
- spec/contextio/connect_token_collection_spec.rb
|
263
|
-
- spec/contextio/connect_token_spec.rb
|
264
|
-
- spec/contextio/email_settings_spec.rb
|
265
|
-
- spec/contextio/oauth_provider_collection_spec.rb
|
266
|
-
- spec/contextio/oauth_provider_spec.rb
|
267
|
-
- spec/contextio/source_collection_spec.rb
|
268
|
-
- spec/contextio/source_spec.rb
|
269
|
-
- spec/contextio/version_spec.rb
|
270
|
-
- spec/contextio_spec.rb
|
256
|
+
- spec/integration/accounts_messages_spec.rb
|
271
257
|
- spec/spec_helper.rb
|
258
|
+
- spec/unit/contextio/account_collection_spec.rb
|
259
|
+
- spec/unit/contextio/account_spec.rb
|
260
|
+
- spec/unit/contextio/api/association_helpers_spec.rb
|
261
|
+
- spec/unit/contextio/api/resource_collection_spec.rb
|
262
|
+
- spec/unit/contextio/api/resource_spec.rb
|
263
|
+
- spec/unit/contextio/api/url_builder_spec.rb
|
264
|
+
- spec/unit/contextio/api_spec.rb
|
265
|
+
- spec/unit/contextio/connect_token_collection_spec.rb
|
266
|
+
- spec/unit/contextio/connect_token_spec.rb
|
267
|
+
- spec/unit/contextio/email_settings_spec.rb
|
268
|
+
- spec/unit/contextio/oauth_provider_collection_spec.rb
|
269
|
+
- spec/unit/contextio/oauth_provider_spec.rb
|
270
|
+
- spec/unit/contextio/source_collection_spec.rb
|
271
|
+
- spec/unit/contextio/source_spec.rb
|
272
|
+
- spec/unit/contextio/version_spec.rb
|
273
|
+
- spec/unit/contextio_spec.rb
|
272
274
|
has_rdoc:
|