contextio 1.2.1 → 1.2.2
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGES.md +11 -0
- data/lib/contextio/api.rb +21 -3
- data/lib/contextio/file.rb +0 -13
- data/lib/contextio/source.rb +14 -0
- data/lib/contextio/source_collection.rb +1 -0
- data/lib/contextio/version.rb +1 -1
- data/spec/contextio/source_spec.rb +17 -0
- metadata +2 -2
data/CHANGES.md
CHANGED
@@ -1,5 +1,16 @@
|
|
1
1
|
# Changes
|
2
2
|
|
3
|
+
## 1.2.2
|
4
|
+
|
5
|
+
* Fix `PUT` and `POST` parameter submission. - Ben Hamill
|
6
|
+
* Added missing `server` argument to `SourceCollection.create`. - Dominik Gehl
|
7
|
+
* Moved erroneous `File.sync_data` and `File.sync!` over to `Source` where it
|
8
|
+
belonged in the first place. - Bram Plessers
|
9
|
+
|
10
|
+
## 1.2.1
|
11
|
+
|
12
|
+
* Fixed syntax error typo in previous release. - Geoff Longman
|
13
|
+
|
3
14
|
## 1.2.0
|
4
15
|
|
5
16
|
* Add `#empty?` and `#size` to resource collections so you can treat them even
|
data/lib/contextio/api.rb
CHANGED
@@ -89,9 +89,8 @@ class ContextIO
|
|
89
89
|
#
|
90
90
|
# @raise [API::Error] if the response code isn't in the 200 or 300 range.
|
91
91
|
def request(method, resource_path, params = {})
|
92
|
-
response =
|
92
|
+
response = oauth_request(method, resource_path, params)
|
93
93
|
body = response.body
|
94
|
-
|
95
94
|
results = JSON.parse(body) unless response.body.empty?
|
96
95
|
|
97
96
|
if response.code =~ /[45]\d\d/
|
@@ -108,7 +107,7 @@ class ContextIO
|
|
108
107
|
end
|
109
108
|
|
110
109
|
def raw_request(method, resource_path, params={})
|
111
|
-
response =
|
110
|
+
response = oauth_request(method, resource_path, params, 'User-Agent' => user_agent_string)
|
112
111
|
|
113
112
|
if response.code =~ /[45]\d\d/
|
114
113
|
raise API::Error, response.message
|
@@ -119,6 +118,25 @@ class ContextIO
|
|
119
118
|
|
120
119
|
private
|
121
120
|
|
121
|
+
# Makes a request signed for OAuth, encoding parameters correctly, etc.
|
122
|
+
#
|
123
|
+
# @param [String, Symbol] method The HTTP verb for the request (lower case).
|
124
|
+
# @param [String] resource_path The path to the resource in question.
|
125
|
+
# @param [{String, Symbol => String, Symbol, Array<String, Symbol>}] params
|
126
|
+
# A Hash of the query parameters for the action represented by this
|
127
|
+
# request.
|
128
|
+
#
|
129
|
+
# @return [Net::HTTP*] The response object from the request.
|
130
|
+
def oauth_request(method, resource_path, params, headers=nil)
|
131
|
+
headers ||= { 'Accept' => 'application/json', 'User-Agent' => user_agent_string }
|
132
|
+
|
133
|
+
if %w(put post).include? method.to_s.downcase
|
134
|
+
token.request(method, path(resource_path), params, headers)
|
135
|
+
else # GET, DELETE, HEAD, etc.
|
136
|
+
token.request(method, path(resource_path, params), headers)
|
137
|
+
end
|
138
|
+
end
|
139
|
+
|
122
140
|
# So that we can accept full URLs, this strips the domain and version number
|
123
141
|
# out and returns just the resource path.
|
124
142
|
#
|
data/lib/contextio/file.rb
CHANGED
@@ -75,18 +75,5 @@ class ContextIO
|
|
75
75
|
return @revisions
|
76
76
|
end
|
77
77
|
|
78
|
-
def sync_data
|
79
|
-
return @sync_data if @sync_data
|
80
|
-
|
81
|
-
sync_hashes = api.request(:get, "#{resource_url}/sync")
|
82
|
-
|
83
|
-
@sync_data = ContextIO::SourceSyncData.new(sync_hashes)
|
84
|
-
|
85
|
-
return @sync_data
|
86
|
-
end
|
87
|
-
|
88
|
-
def sync!
|
89
|
-
api.request(:post, "#{resource_url}/sync")['success']
|
90
|
-
end
|
91
78
|
end
|
92
79
|
end
|
data/lib/contextio/source.rb
CHANGED
@@ -51,5 +51,19 @@ class ContextIO
|
|
51
51
|
def delete
|
52
52
|
api.request(:delete, resource_url)['success']
|
53
53
|
end
|
54
|
+
|
55
|
+
def sync_data
|
56
|
+
return @sync_data if @sync_data
|
57
|
+
|
58
|
+
sync_hashes = api.request(:get, "#{resource_url}/sync")
|
59
|
+
|
60
|
+
@sync_data = ContextIO::SourceSyncData.new(sync_hashes)
|
61
|
+
|
62
|
+
return @sync_data
|
63
|
+
end
|
64
|
+
|
65
|
+
def sync!
|
66
|
+
api.request(:post, "#{resource_url}/sync")['success']
|
67
|
+
end
|
54
68
|
end
|
55
69
|
end
|
data/lib/contextio/version.rb
CHANGED
@@ -49,4 +49,21 @@ describe ContextIO::Source do
|
|
49
49
|
subject.update(sync_period: '4h')
|
50
50
|
end
|
51
51
|
end
|
52
|
+
|
53
|
+
describe ".sync!" do
|
54
|
+
before do
|
55
|
+
api.stub(:request).and_return({'success' => true})
|
56
|
+
end
|
57
|
+
|
58
|
+
subject { ContextIO::Source.new(api, resource_url: 'resource_url', sync_period: '1h') }
|
59
|
+
|
60
|
+
it "syncs to the api" do
|
61
|
+
api.should_receive(:request).with(
|
62
|
+
:post,
|
63
|
+
'resource_url/sync'
|
64
|
+
)
|
65
|
+
|
66
|
+
subject.sync!
|
67
|
+
end
|
68
|
+
end
|
52
69
|
end
|
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.2
|
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-
|
12
|
+
date: 2013-02-12 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: oauth
|