api_client 0.5.20 → 0.5.26
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/CHANGELOG.md +20 -0
- data/LICENSE +201 -22
- data/README.md +11 -4
- data/lib/api_client/connection/basic.rb +6 -0
- data/lib/api_client/errors.rb +3 -0
- data/lib/api_client/version.rb +1 -1
- data/spec/api_client/connection/basic_spec.rb +21 -0
- metadata +14 -18
- data/.gitignore +0 -9
- data/.rspec +0 -1
- data/.travis.yml +0 -13
- data/api_client.gemspec +0 -48
- data/examples/digg.rb +0 -31
- data/examples/flickr.rb +0 -37
- data/examples/github.rb +0 -52
- data/examples/highrise.rb +0 -41
- data/examples/twitter.rb +0 -34
- data/examples/twitter_oauth.rb +0 -36
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 810d32749cc1ee8060c90cd98bfb13fe98739617043ba428f624e1203cb446d9
|
4
|
+
data.tar.gz: 90a3cb0f587a1f1bc0767080cd36d292dbd751cdd6817e6e5cc396873c3b4960
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 97062be5359c222fe60a142dad7a944b26cb8eb8bf572353932ee5cbe1c8b5cd5356174c689ca45557b5ee7ecab56b1a1e3fc1f9bd71e580d9c01f943d46ca4c
|
7
|
+
data.tar.gz: 99df6ebe27b699fb26a40d7069502c2e85d4afec520bfba5f202de28993631ac6198e9302c4d02b72fc5a8cd3621a3969f95be003ac139c8bfd469f4735d415f
|
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,23 @@
|
|
1
|
+
# 0.5.26
|
2
|
+
|
3
|
+
* Add support for HTTP status code: 412 Precondition Failed
|
4
|
+
|
5
|
+
# 0.5.25
|
6
|
+
|
7
|
+
* Fix broken gem build (gemspec files)
|
8
|
+
|
9
|
+
# 0.5.23
|
10
|
+
|
11
|
+
* Add support for HTTP status code: 423 Locked
|
12
|
+
|
13
|
+
# 0.5.22
|
14
|
+
|
15
|
+
* Add constraint on faraday < 1.0.0 as it breaks compatibility
|
16
|
+
|
17
|
+
# 0.5.21
|
18
|
+
|
19
|
+
* add support for http 410 status code
|
20
|
+
|
1
21
|
# 0.5.20
|
2
22
|
|
3
23
|
* brought back jruby support
|
data/LICENSE
CHANGED
@@ -1,22 +1,201 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
1
|
+
Apache License
|
2
|
+
Version 2.0, January 2004
|
3
|
+
http://www.apache.org/licenses/
|
4
|
+
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
6
|
+
|
7
|
+
1. Definitions.
|
8
|
+
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
11
|
+
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
13
|
+
the copyright owner that is granting the License.
|
14
|
+
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
16
|
+
other entities that control, are controlled by, or are under common
|
17
|
+
control with that entity. For the purposes of this definition,
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
19
|
+
direction or management of such entity, whether by contract or
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
22
|
+
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
24
|
+
exercising permissions granted by this License.
|
25
|
+
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
27
|
+
including but not limited to software source code, documentation
|
28
|
+
source, and configuration files.
|
29
|
+
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
31
|
+
transformation or translation of a Source form, including but
|
32
|
+
not limited to compiled object code, generated documentation,
|
33
|
+
and conversions to other media types.
|
34
|
+
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
36
|
+
Object form, made available under the License, as indicated by a
|
37
|
+
copyright notice that is included in or attached to the work
|
38
|
+
(an example is provided in the Appendix below).
|
39
|
+
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
43
|
+
represent, as a whole, an original work of authorship. For the purposes
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
46
|
+
the Work and Derivative Works thereof.
|
47
|
+
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
49
|
+
the original version of the Work and any modifications or additions
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
51
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
52
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
53
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
61
|
+
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
63
|
+
on behalf of whom a Contribution has been received by Licensor and
|
64
|
+
subsequently incorporated within the Work.
|
65
|
+
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
72
|
+
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
78
|
+
where such license applies only to those patent claims licensable
|
79
|
+
by such Contributor that are necessarily infringed by their
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
82
|
+
institute patent litigation against any entity (including a
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
85
|
+
or contributory patent infringement, then any patent licenses
|
86
|
+
granted to You under this License for that Work shall terminate
|
87
|
+
as of the date such litigation is filed.
|
88
|
+
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
91
|
+
modifications, and in Source or Object form, provided that You
|
92
|
+
meet the following conditions:
|
93
|
+
|
94
|
+
(a) You must give any other recipients of the Work or
|
95
|
+
Derivative Works a copy of this License; and
|
96
|
+
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
98
|
+
stating that You changed the files; and
|
99
|
+
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
102
|
+
attribution notices from the Source form of the Work,
|
103
|
+
excluding those notices that do not pertain to any part of
|
104
|
+
the Derivative Works; and
|
105
|
+
|
106
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
107
|
+
distribution, then any Derivative Works that You distribute must
|
108
|
+
include a readable copy of the attribution notices contained
|
109
|
+
within such NOTICE file, excluding those notices that do not
|
110
|
+
pertain to any part of the Derivative Works, in at least one
|
111
|
+
of the following places: within a NOTICE text file distributed
|
112
|
+
as part of the Derivative Works; within the Source form or
|
113
|
+
documentation, if provided along with the Derivative Works; or,
|
114
|
+
within a display generated by the Derivative Works, if and
|
115
|
+
wherever such third-party notices normally appear. The contents
|
116
|
+
of the NOTICE file are for informational purposes only and
|
117
|
+
do not modify the License. You may add Your own attribution
|
118
|
+
notices within Derivative Works that You distribute, alongside
|
119
|
+
or as an addendum to the NOTICE text from the Work, provided
|
120
|
+
that such additional attribution notices cannot be construed
|
121
|
+
as modifying the License.
|
122
|
+
|
123
|
+
You may add Your own copyright statement to Your modifications and
|
124
|
+
may provide additional or different license terms and conditions
|
125
|
+
for use, reproduction, or distribution of Your modifications, or
|
126
|
+
for any such Derivative Works as a whole, provided Your use,
|
127
|
+
reproduction, and distribution of the Work otherwise complies with
|
128
|
+
the conditions stated in this License.
|
129
|
+
|
130
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
131
|
+
any Contribution intentionally submitted for inclusion in the Work
|
132
|
+
by You to the Licensor shall be under the terms and conditions of
|
133
|
+
this License, without any additional terms or conditions.
|
134
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
135
|
+
the terms of any separate license agreement you may have executed
|
136
|
+
with Licensor regarding such Contributions.
|
137
|
+
|
138
|
+
6. Trademarks. This License does not grant permission to use the trade
|
139
|
+
names, trademarks, service marks, or product names of the Licensor,
|
140
|
+
except as required for reasonable and customary use in describing the
|
141
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
142
|
+
|
143
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
144
|
+
agreed to in writing, Licensor provides the Work (and each
|
145
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
146
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
147
|
+
implied, including, without limitation, any warranties or conditions
|
148
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
149
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
150
|
+
appropriateness of using or redistributing the Work and assume any
|
151
|
+
risks associated with Your exercise of permissions under this License.
|
152
|
+
|
153
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
154
|
+
whether in tort (including negligence), contract, or otherwise,
|
155
|
+
unless required by applicable law (such as deliberate and grossly
|
156
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
157
|
+
liable to You for damages, including any direct, indirect, special,
|
158
|
+
incidental, or consequential damages of any character arising as a
|
159
|
+
result of this License or out of the use or inability to use the
|
160
|
+
Work (including but not limited to damages for loss of goodwill,
|
161
|
+
work stoppage, computer failure or malfunction, or any and all
|
162
|
+
other commercial damages or losses), even if such Contributor
|
163
|
+
has been advised of the possibility of such damages.
|
164
|
+
|
165
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
166
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
167
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
168
|
+
or other liability obligations and/or rights consistent with this
|
169
|
+
License. However, in accepting such obligations, You may act only
|
170
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
171
|
+
of any other Contributor, and only if You agree to indemnify,
|
172
|
+
defend, and hold each Contributor harmless for any liability
|
173
|
+
incurred by, or claims asserted against, such Contributor by reason
|
174
|
+
of your accepting any such warranty or additional liability.
|
175
|
+
|
176
|
+
END OF TERMS AND CONDITIONS
|
177
|
+
|
178
|
+
APPENDIX: How to apply the Apache License to your work.
|
179
|
+
|
180
|
+
To apply the Apache License to your work, attach the following
|
181
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
182
|
+
replaced with your own identifying information. (Don't include
|
183
|
+
the brackets!) The text should be enclosed in the appropriate
|
184
|
+
comment syntax for the file format. We also recommend that a
|
185
|
+
file or class name and description of purpose be included on the
|
186
|
+
same "printed page" as the copyright notice for easier
|
187
|
+
identification within third-party archives.
|
188
|
+
|
189
|
+
Copyright 2011 Zendesk
|
190
|
+
|
191
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
192
|
+
you may not use this file except in compliance with the License.
|
193
|
+
You may obtain a copy of the License at
|
194
|
+
|
195
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
196
|
+
|
197
|
+
Unless required by applicable law or agreed to in writing, software
|
198
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
199
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
200
|
+
See the License for the specific language governing permissions and
|
201
|
+
limitations under the License.
|
data/README.md
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
ApiClient
|
1
|
+
ApiClient ![Tests](https://github.com/zendesk/api_client/workflows/Tests/badge.svg)
|
2
2
|
=========
|
3
3
|
|
4
4
|
ApiClient is an experimental builder for HTTP API clients. The goal is to provide a easy to use engine for constructing queries and map the responses to instances of Hashie::Mash subclasses.
|
@@ -154,7 +154,14 @@ ApiClient.logger.level = Logger::INFO
|
|
154
154
|
|
155
155
|
```
|
156
156
|
|
157
|
-
|
158
|
-
---------
|
157
|
+
## Releasing new version of gem
|
159
158
|
|
160
|
-
|
159
|
+
1. Update version in [lib/api_client/version.rb](lib/api_client/version.rb) and push to `master`
|
160
|
+
2. Create new GitHub release with tag name starting with `v` and the version, for example `v1.0.0`
|
161
|
+
3. Gem will be automatically built and pushed to rubygems.org with GitHub Action
|
162
|
+
|
163
|
+
## Copyright and license
|
164
|
+
|
165
|
+
Copyright 2011 Zendesk
|
166
|
+
|
167
|
+
Licensed under the [Apache License, Version 2.0](LICENSE)
|
@@ -107,8 +107,14 @@ module ApiClient
|
|
107
107
|
raise ApiClient::Errors::Unsupported.new(nil, request, response)
|
108
108
|
when 409
|
109
109
|
raise ApiClient::Errors::Conflict.new(nil, request, response)
|
110
|
+
when 410
|
111
|
+
raise ApiClient::Errors::Gone.new(nil, request, response)
|
112
|
+
when 412
|
113
|
+
raise ApiClient::Errors::PreconditionFailed.new(nil, request, response)
|
110
114
|
when 422
|
111
115
|
raise ApiClient::Errors::UnprocessableEntity.new(response.body, request, response)
|
116
|
+
when 423
|
117
|
+
raise ApiClient::Errors::Locked.new(response.body, request, response)
|
112
118
|
when 429
|
113
119
|
raise ApiClient::Errors::TooManyRequests.new(response.body, request, response)
|
114
120
|
when 300..399
|
data/lib/api_client/errors.rb
CHANGED
@@ -21,8 +21,11 @@ module ApiClient
|
|
21
21
|
class BadRequest < ApiClientError; end
|
22
22
|
class Unsupported < ApiClientError; end
|
23
23
|
class Conflict < ApiClientError; end
|
24
|
+
class Gone < ApiClientError; end
|
24
25
|
class ServerError < ApiClientError; end
|
25
26
|
class UnprocessableEntity < ApiClientError; end
|
27
|
+
class PreconditionFailed < ApiClientError; end
|
28
|
+
class Locked < ApiClientError; end
|
26
29
|
class TooManyRequests < ApiClientError; end
|
27
30
|
end
|
28
31
|
|
data/lib/api_client/version.rb
CHANGED
@@ -142,6 +142,20 @@ describe ApiClient::Connection::Basic do
|
|
142
142
|
}.should raise_error(ApiClient::Errors::Conflict, "Status code: 409")
|
143
143
|
end
|
144
144
|
|
145
|
+
it "raises an ApiClient::Errors::Gone if status is 410" do
|
146
|
+
@response.env[:status] = 410
|
147
|
+
lambda {
|
148
|
+
@instance.send :handle_response, request, @response
|
149
|
+
}.should raise_error(ApiClient::Errors::Gone, "Status code: 410")
|
150
|
+
end
|
151
|
+
|
152
|
+
it "raises an ApiClient::Errors::PreconditionFailed if status is 412" do
|
153
|
+
@response.env[:status] = 412
|
154
|
+
lambda {
|
155
|
+
@instance.send :handle_response, request, @response
|
156
|
+
}.should raise_error(ApiClient::Errors::PreconditionFailed, "Status code: 412")
|
157
|
+
end
|
158
|
+
|
145
159
|
it "raises an ApiClient::Errors::Unsupported if status is 422" do
|
146
160
|
@response.env[:status] = 422
|
147
161
|
lambda {
|
@@ -149,6 +163,13 @@ describe ApiClient::Connection::Basic do
|
|
149
163
|
}.should raise_error(ApiClient::Errors::UnprocessableEntity, @response.body)
|
150
164
|
end
|
151
165
|
|
166
|
+
it "raises an ApiClient::Errors::Locked if status is 423" do
|
167
|
+
@response.env[:status] = 423
|
168
|
+
lambda {
|
169
|
+
@instance.send :handle_response, request, @response
|
170
|
+
}.should raise_error(ApiClient::Errors::Locked, @response.body)
|
171
|
+
end
|
172
|
+
|
152
173
|
it "raises an ApiClient::Errors::TooManyRequests if status is 429" do
|
153
174
|
@response.env[:status] = 429
|
154
175
|
lambda {
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: api_client
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.5.
|
4
|
+
version: 0.5.26
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
|
-
-
|
7
|
+
- Zendesk
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2021-05-05 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rspec
|
@@ -59,6 +59,9 @@ dependencies:
|
|
59
59
|
- - ">="
|
60
60
|
- !ruby/object:Gem::Version
|
61
61
|
version: 0.8.1
|
62
|
+
- - "<"
|
63
|
+
- !ruby/object:Gem::Version
|
64
|
+
version: 1.0.0
|
62
65
|
type: :runtime
|
63
66
|
prerelease: false
|
64
67
|
version_requirements: !ruby/object:Gem::Requirement
|
@@ -66,6 +69,9 @@ dependencies:
|
|
66
69
|
- - ">="
|
67
70
|
- !ruby/object:Gem::Version
|
68
71
|
version: 0.8.1
|
72
|
+
- - "<"
|
73
|
+
- !ruby/object:Gem::Version
|
74
|
+
version: 1.0.0
|
69
75
|
- !ruby/object:Gem::Dependency
|
70
76
|
name: multi_json
|
71
77
|
requirement: !ruby/object:Gem::Requirement
|
@@ -82,27 +88,17 @@ dependencies:
|
|
82
88
|
version: 1.6.1
|
83
89
|
description: API client builder
|
84
90
|
email:
|
85
|
-
-
|
91
|
+
- opensource@zendesk.com
|
86
92
|
executables: []
|
87
93
|
extensions: []
|
88
94
|
extra_rdoc_files: []
|
89
95
|
files:
|
90
|
-
- ".gitignore"
|
91
|
-
- ".rspec"
|
92
|
-
- ".travis.yml"
|
93
96
|
- CHANGELOG.md
|
94
97
|
- Gemfile
|
95
98
|
- LICENSE
|
96
99
|
- Makefile
|
97
100
|
- README.md
|
98
101
|
- Rakefile
|
99
|
-
- api_client.gemspec
|
100
|
-
- examples/digg.rb
|
101
|
-
- examples/flickr.rb
|
102
|
-
- examples/github.rb
|
103
|
-
- examples/highrise.rb
|
104
|
-
- examples/twitter.rb
|
105
|
-
- examples/twitter_oauth.rb
|
106
102
|
- lib/api_client.rb
|
107
103
|
- lib/api_client/base.rb
|
108
104
|
- lib/api_client/connection/abstract.rb
|
@@ -147,7 +143,8 @@ files:
|
|
147
143
|
- spec/spec_helper.rb
|
148
144
|
- spec/support/matchers.rb
|
149
145
|
homepage: https://github.com/futuresimple/api_client
|
150
|
-
licenses:
|
146
|
+
licenses:
|
147
|
+
- Apache License Version 2.0
|
151
148
|
metadata: {}
|
152
149
|
post_install_message:
|
153
150
|
rdoc_options: []
|
@@ -157,15 +154,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
157
154
|
requirements:
|
158
155
|
- - ">="
|
159
156
|
- !ruby/object:Gem::Version
|
160
|
-
version:
|
157
|
+
version: 2.2.0
|
161
158
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
162
159
|
requirements:
|
163
160
|
- - ">="
|
164
161
|
- !ruby/object:Gem::Version
|
165
162
|
version: '0'
|
166
163
|
requirements: []
|
167
|
-
|
168
|
-
rubygems_version: 2.5.2.2
|
164
|
+
rubygems_version: 3.3.0.dev
|
169
165
|
signing_key:
|
170
166
|
specification_version: 3
|
171
167
|
summary: API client builder
|
data/.gitignore
DELETED
data/.rspec
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
--color
|
data/.travis.yml
DELETED
data/api_client.gemspec
DELETED
@@ -1,48 +0,0 @@
|
|
1
|
-
# -*- encoding: utf-8 -*-
|
2
|
-
$:.push File.expand_path("../lib", __FILE__)
|
3
|
-
require "api_client/version"
|
4
|
-
|
5
|
-
Gem::Specification.new do |s|
|
6
|
-
s.name = "api_client"
|
7
|
-
s.version = ApiClient::VERSION
|
8
|
-
s.authors = ["Marcin Bunsch"]
|
9
|
-
s.email = ["marcin@futuresimple.com"]
|
10
|
-
s.homepage = "https://github.com/futuresimple/api_client"
|
11
|
-
s.summary = %q{API client builder}
|
12
|
-
s.description = %q{API client builder}
|
13
|
-
|
14
|
-
s.rubyforge_project = "api_client"
|
15
|
-
|
16
|
-
# Declare runtime dependencies here:
|
17
|
-
def s.add_runtime_dependencies(method)
|
18
|
-
if RUBY_PLATFORM == "java"
|
19
|
-
send method, 'jrjackson'
|
20
|
-
else
|
21
|
-
send method, 'yajl-ruby'
|
22
|
-
end
|
23
|
-
|
24
|
-
send method, 'hashie', [">= 2.0.5"]
|
25
|
-
send method, 'faraday', [">= 0.8.1"]
|
26
|
-
send method, 'multi_json', [">= 1.6.1"]
|
27
|
-
end
|
28
|
-
|
29
|
-
# Declare development dependencies here:
|
30
|
-
s.add_development_dependency 'rspec', '2.14.1'
|
31
|
-
|
32
|
-
if s.respond_to? :specification_version then
|
33
|
-
s.specification_version = 3
|
34
|
-
|
35
|
-
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
36
|
-
s.add_runtime_dependencies(:add_runtime_dependency)
|
37
|
-
else
|
38
|
-
s.add_runtime_dependencies(:add_dependency)
|
39
|
-
end
|
40
|
-
else
|
41
|
-
s.add_runtime_dependencies(:add_dependency)
|
42
|
-
end
|
43
|
-
|
44
|
-
s.files = `git ls-files`.split("\n")
|
45
|
-
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
46
|
-
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
47
|
-
s.require_paths = ["lib"]
|
48
|
-
end
|
data/examples/digg.rb
DELETED
@@ -1,31 +0,0 @@
|
|
1
|
-
require "rubygems"
|
2
|
-
require "bundler/setup"
|
3
|
-
require "api_client"
|
4
|
-
|
5
|
-
module Digg
|
6
|
-
|
7
|
-
class Base < ApiClient::Base
|
8
|
-
|
9
|
-
always do
|
10
|
-
endpoint "http://services.digg.com"
|
11
|
-
params :type => 'json'
|
12
|
-
end
|
13
|
-
|
14
|
-
end
|
15
|
-
|
16
|
-
class Collection < Base
|
17
|
-
|
18
|
-
def self.diggs
|
19
|
-
Digg.build get('/2.0/digg.getAll')['diggs']
|
20
|
-
end
|
21
|
-
|
22
|
-
end
|
23
|
-
|
24
|
-
class Digg < Base
|
25
|
-
end
|
26
|
-
|
27
|
-
end
|
28
|
-
|
29
|
-
Digg::Collection.diggs.each do |digg|
|
30
|
-
puts "#{digg.user.name}: #{digg.item.title}"
|
31
|
-
end
|
data/examples/flickr.rb
DELETED
@@ -1,37 +0,0 @@
|
|
1
|
-
require "rubygems"
|
2
|
-
require "bundler/setup"
|
3
|
-
require "./examples/config" if File.exists?('examples/config.rb')
|
4
|
-
require "api_client"
|
5
|
-
|
6
|
-
module Flickr
|
7
|
-
|
8
|
-
class Base < ApiClient::Base
|
9
|
-
always do
|
10
|
-
endpoint "http://api.flickr.com"
|
11
|
-
params :api_key => FLICKR_API_KEY,
|
12
|
-
:format => 'json',
|
13
|
-
:nojsoncallback => 1
|
14
|
-
end
|
15
|
-
end
|
16
|
-
|
17
|
-
class Collection < Base
|
18
|
-
|
19
|
-
def self.interesting
|
20
|
-
build params(:method => 'flickr.interestingness.getList').
|
21
|
-
get("/services/rest")
|
22
|
-
end
|
23
|
-
|
24
|
-
def photos
|
25
|
-
Photo.build self['photos']['photo']
|
26
|
-
end
|
27
|
-
|
28
|
-
end
|
29
|
-
|
30
|
-
class Photo < Base
|
31
|
-
end
|
32
|
-
|
33
|
-
end
|
34
|
-
|
35
|
-
Flickr::Collection.interesting.photos.each do |photo|
|
36
|
-
puts photo.title
|
37
|
-
end
|
data/examples/github.rb
DELETED
@@ -1,52 +0,0 @@
|
|
1
|
-
require "rubygems"
|
2
|
-
require "bundler/setup"
|
3
|
-
require "./examples/config" if File.exists?('examples/config.rb')
|
4
|
-
require "api_client"
|
5
|
-
require "time"
|
6
|
-
|
7
|
-
module Github
|
8
|
-
|
9
|
-
class Base < ApiClient::Base
|
10
|
-
namespace false
|
11
|
-
|
12
|
-
always do
|
13
|
-
endpoint "https://api.github.com"
|
14
|
-
end
|
15
|
-
end
|
16
|
-
|
17
|
-
class User < Base
|
18
|
-
|
19
|
-
def self.find(name)
|
20
|
-
fetch("/users/#{name}")
|
21
|
-
end
|
22
|
-
|
23
|
-
def events
|
24
|
-
Github::Event.fetch("/users/#{login}/events")
|
25
|
-
end
|
26
|
-
|
27
|
-
def received_events
|
28
|
-
Github::Event.fetch("/users/#{login}/received_events")
|
29
|
-
end
|
30
|
-
|
31
|
-
end
|
32
|
-
|
33
|
-
class Event < Base
|
34
|
-
|
35
|
-
def created_at
|
36
|
-
Time.parse self['created_at']
|
37
|
-
end
|
38
|
-
|
39
|
-
end
|
40
|
-
|
41
|
-
end
|
42
|
-
|
43
|
-
user = Github::User.find("marcinbunsch")
|
44
|
-
|
45
|
-
user.events.each do |event|
|
46
|
-
case event.type
|
47
|
-
when "FollowEvent"
|
48
|
-
puts "#{event.created_at} #{event.payload.target.login}: #{event.type}"
|
49
|
-
else
|
50
|
-
puts "#{event.created_at} #{event.repo.name} : #{event.type}"
|
51
|
-
end
|
52
|
-
end
|
data/examples/highrise.rb
DELETED
@@ -1,41 +0,0 @@
|
|
1
|
-
require "rubygems"
|
2
|
-
require "bundler/setup"
|
3
|
-
require "./examples/config" if File.exists?('examples/config.rb')
|
4
|
-
require "api_client"
|
5
|
-
require "multi_xml"
|
6
|
-
|
7
|
-
module Highrise
|
8
|
-
|
9
|
-
class Base < ApiClient::Resource::Base
|
10
|
-
format :xml
|
11
|
-
|
12
|
-
# In this hook we set the basic auth provided in the options
|
13
|
-
connection do |connection|
|
14
|
-
connection.handler.basic_auth connection.options[:user], connection.options[:pass]
|
15
|
-
end
|
16
|
-
|
17
|
-
always do
|
18
|
-
endpoint HIGHRISE_URL
|
19
|
-
options(:user => HIGHRISE_TOKEN, :pass => 'X')
|
20
|
-
end
|
21
|
-
|
22
|
-
end
|
23
|
-
|
24
|
-
class Person < Base
|
25
|
-
namespace false
|
26
|
-
|
27
|
-
always do
|
28
|
-
path "people"
|
29
|
-
end
|
30
|
-
|
31
|
-
def self.build_one(hash)
|
32
|
-
hash.has_key?('people') ? build_many(hash['people']) : super(hash)
|
33
|
-
end
|
34
|
-
|
35
|
-
end
|
36
|
-
|
37
|
-
end
|
38
|
-
|
39
|
-
Highrise::Person.find_all.each do |person|
|
40
|
-
puts "#{person.first_name} #{person.last_name}"
|
41
|
-
end
|
data/examples/twitter.rb
DELETED
@@ -1,34 +0,0 @@
|
|
1
|
-
require "rubygems"
|
2
|
-
require "bundler/setup"
|
3
|
-
require "api_client"
|
4
|
-
|
5
|
-
module Twitter
|
6
|
-
|
7
|
-
class Base < ApiClient::Base
|
8
|
-
always do
|
9
|
-
endpoint "http://api.twitter.com/"
|
10
|
-
end
|
11
|
-
end
|
12
|
-
|
13
|
-
class Tweet < Base
|
14
|
-
end
|
15
|
-
|
16
|
-
class User < Base
|
17
|
-
|
18
|
-
def self.find_by_username(name)
|
19
|
-
params(:screen_name => name).fetch("/1/users/show.json")
|
20
|
-
end
|
21
|
-
|
22
|
-
def tweets
|
23
|
-
Tweet.params(:screen_name => self.screen_name).fetch("/1/statuses/user_timeline.json")
|
24
|
-
end
|
25
|
-
|
26
|
-
end
|
27
|
-
|
28
|
-
end
|
29
|
-
|
30
|
-
user = Twitter::User.find_by_username("marcinbunsch")
|
31
|
-
puts user.name
|
32
|
-
user.tweets.each do |tweet|
|
33
|
-
puts " #{tweet.text}"
|
34
|
-
end
|
data/examples/twitter_oauth.rb
DELETED
@@ -1,36 +0,0 @@
|
|
1
|
-
require "rubygems"
|
2
|
-
require "bundler/setup"
|
3
|
-
require "./examples/config" if File.exists?('examples/config.rb')
|
4
|
-
require "api_client"
|
5
|
-
|
6
|
-
module TwitterOauth
|
7
|
-
|
8
|
-
class Base < ApiClient::Base
|
9
|
-
|
10
|
-
always do
|
11
|
-
endpoint "https://api.twitter.com/"
|
12
|
-
adapter :oauth
|
13
|
-
|
14
|
-
options :oauth => {
|
15
|
-
:consumer_key => TWITTER_CONSUMER_KEY, :consumer_secret => TWITTER_CONSUMER_SECRET
|
16
|
-
}
|
17
|
-
|
18
|
-
end
|
19
|
-
|
20
|
-
end
|
21
|
-
|
22
|
-
class Tweet < Base
|
23
|
-
|
24
|
-
def self.tweet(message)
|
25
|
-
build post('/1/statuses/update.json', :status => message)
|
26
|
-
end
|
27
|
-
|
28
|
-
end
|
29
|
-
|
30
|
-
end
|
31
|
-
|
32
|
-
config = { :token => TWITTER_TOKEN, :token_secret => TWITTER_SECRET }
|
33
|
-
|
34
|
-
message = TwitterOauth::Tweet.options(:oauth => config).tweet("test #{Time.now.to_i}")
|
35
|
-
|
36
|
-
puts message.text
|