api_client 0.5.24 → 0.6.0
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 +5 -5
- data/CHANGELOG.md +13 -0
- data/LICENSE +1 -1
- data/README.md +8 -2
- data/lib/api_client/connection/basic.rb +3 -1
- data/lib/api_client/errors.rb +1 -0
- data/lib/api_client/version.rb +1 -1
- data/spec/api_client/connection/basic_spec.rb +14 -7
- data/spec/api_client/connection/oauth_spec.rb +9 -13
- metadata +6 -17
- data/.gitignore +0 -9
- data/.rspec +0 -1
- data/.travis.yml +0 -13
- data/api_client.gemspec +0 -49
- 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: 65b639c41de486bf27f118c1d6d3860b77e582d1fd03213801744e5e985938af
|
|
4
|
+
data.tar.gz: 7c774f56f8d550c49586ab2a1237db52bf052c0122058393566cc4f36cb8636a
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 3f2fb5535e7b62aae77d2947a7e97cf1ea58506ed7348b839864194a6d6ac4aac5222011cedb095fa16a972be3e0835bae5e6269d29f1836f02edc6ffbe3a7be
|
|
7
|
+
data.tar.gz: 1d85041923882d0713a2f065e25484ac4ad8992f68085a9f24296b11b6b92bdc791b3de5b44a5ed6e5dc2be520d5b5a7c9d3c5f441466fc2d082ea3ac6ffeb9f
|
data/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,16 @@
|
|
|
1
|
+
# 0.6.0
|
|
2
|
+
|
|
3
|
+
* Add support for faraday gem version >= 1.0.0 and < 2.0.0
|
|
4
|
+
* Drop support for Ruby < 2.3
|
|
5
|
+
|
|
6
|
+
# 0.5.26
|
|
7
|
+
|
|
8
|
+
* Add support for HTTP status code: 412 Precondition Failed
|
|
9
|
+
|
|
10
|
+
# 0.5.25
|
|
11
|
+
|
|
12
|
+
* Fix broken gem build (gemspec files)
|
|
13
|
+
|
|
1
14
|
# 0.5.23
|
|
2
15
|
|
|
3
16
|
* Add support for HTTP status code: 423 Locked
|
data/LICENSE
CHANGED
|
@@ -186,7 +186,7 @@
|
|
|
186
186
|
same "printed page" as the copyright notice for easier
|
|
187
187
|
identification within third-party archives.
|
|
188
188
|
|
|
189
|
-
Copyright
|
|
189
|
+
Copyright 2011 Zendesk
|
|
190
190
|
|
|
191
191
|
Licensed under the Apache License, Version 2.0 (the "License");
|
|
192
192
|
you may not use this file except in compliance with the License.
|
data/README.md
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
ApiClient
|
|
1
|
+
ApiClient 
|
|
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,8 +154,14 @@ ApiClient.logger.level = Logger::INFO
|
|
|
154
154
|
|
|
155
155
|
```
|
|
156
156
|
|
|
157
|
+
## Releasing new version of gem
|
|
158
|
+
|
|
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
|
+
|
|
157
163
|
## Copyright and license
|
|
158
164
|
|
|
159
|
-
Copyright
|
|
165
|
+
Copyright 2011 Zendesk
|
|
160
166
|
|
|
161
167
|
Licensed under the [Apache License, Version 2.0](LICENSE)
|
|
@@ -88,7 +88,7 @@ module ApiClient
|
|
|
88
88
|
response = @handler.send(method, path, data, headers)
|
|
89
89
|
request = { :method => method, :path => path, :data => data}
|
|
90
90
|
handle_response(request, response)
|
|
91
|
-
rescue Faraday::
|
|
91
|
+
rescue Faraday::ConnectionFailed => e
|
|
92
92
|
raise ApiClient::Errors::ConnectionFailed.new(e.message, request, response)
|
|
93
93
|
end
|
|
94
94
|
|
|
@@ -109,6 +109,8 @@ module ApiClient
|
|
|
109
109
|
raise ApiClient::Errors::Conflict.new(nil, request, response)
|
|
110
110
|
when 410
|
|
111
111
|
raise ApiClient::Errors::Gone.new(nil, request, response)
|
|
112
|
+
when 412
|
|
113
|
+
raise ApiClient::Errors::PreconditionFailed.new(nil, request, response)
|
|
112
114
|
when 422
|
|
113
115
|
raise ApiClient::Errors::UnprocessableEntity.new(response.body, request, response)
|
|
114
116
|
when 423
|
data/lib/api_client/errors.rb
CHANGED
|
@@ -24,6 +24,7 @@ module ApiClient
|
|
|
24
24
|
class Gone < ApiClientError; end
|
|
25
25
|
class ServerError < ApiClientError; end
|
|
26
26
|
class UnprocessableEntity < ApiClientError; end
|
|
27
|
+
class PreconditionFailed < ApiClientError; end
|
|
27
28
|
class Locked < ApiClientError; end
|
|
28
29
|
class TooManyRequests < ApiClientError; end
|
|
29
30
|
end
|
data/lib/api_client/version.rb
CHANGED
|
@@ -7,21 +7,21 @@ describe ApiClient::Connection::Basic do
|
|
|
7
7
|
instance.inspect.should == '#<ApiClient::Connection::Basic endpoint: "http://google.com">'
|
|
8
8
|
end
|
|
9
9
|
|
|
10
|
+
it "uses correct adapter" do
|
|
11
|
+
instance = ApiClient::Connection::Basic.new("http://google.com")
|
|
12
|
+
expect(instance.handler.builder.adapter.name).to eq("Faraday::Adapter::NetHttp")
|
|
13
|
+
end
|
|
14
|
+
|
|
10
15
|
it "adds basic middlewares to faraday" do
|
|
11
16
|
instance = ApiClient::Connection::Basic.new("http://google.com")
|
|
12
|
-
instance.handler.builder.handlers.collect(&:name).
|
|
17
|
+
expect(instance.handler.builder.handlers.collect(&:name)).to include("Faraday::Request::UrlEncoded")
|
|
13
18
|
end
|
|
14
19
|
|
|
15
20
|
it "adds the logger middlewares to faraday if ApiClient.logger is available" do
|
|
16
21
|
logger = double
|
|
17
22
|
ApiClient.stub(:logger).and_return(logger)
|
|
18
23
|
instance = ApiClient::Connection::Basic.new("http://google.com")
|
|
19
|
-
instance.handler.builder.handlers.collect(&:name).
|
|
20
|
-
"ApiClient::Connection::Middlewares::Request::Logger",
|
|
21
|
-
"Faraday::Request::UrlEncoded",
|
|
22
|
-
"Faraday::Adapter::NetHttp"
|
|
23
|
-
]
|
|
24
|
-
|
|
24
|
+
expect(instance.handler.builder.handlers.collect(&:name)).to include("ApiClient::Connection::Middlewares::Request::Logger", "Faraday::Request::UrlEncoded")
|
|
25
25
|
end
|
|
26
26
|
|
|
27
27
|
it "creates a Faraday object on initialize" do
|
|
@@ -149,6 +149,13 @@ describe ApiClient::Connection::Basic do
|
|
|
149
149
|
}.should raise_error(ApiClient::Errors::Gone, "Status code: 410")
|
|
150
150
|
end
|
|
151
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
|
+
|
|
152
159
|
it "raises an ApiClient::Errors::Unsupported if status is 422" do
|
|
153
160
|
@response.env[:status] = 422
|
|
154
161
|
lambda {
|
|
@@ -2,26 +2,22 @@ require "spec_helper"
|
|
|
2
2
|
|
|
3
3
|
describe ApiClient::Connection::Oauth do
|
|
4
4
|
|
|
5
|
+
it "uses correct adapter" do
|
|
6
|
+
instance = ApiClient::Connection::Oauth.new("http://google.com")
|
|
7
|
+
expect(instance.handler.builder.adapter.name).to eq("Faraday::Adapter::NetHttp")
|
|
8
|
+
end
|
|
9
|
+
|
|
5
10
|
it "adds basic middlewares to faraday" do
|
|
6
11
|
instance = ApiClient::Connection::Oauth.new("http://google.com")
|
|
7
|
-
instance.handler.builder.handlers.collect(&:name)
|
|
8
|
-
"ApiClient::Connection::Middlewares::Request::OAuth",
|
|
9
|
-
"Faraday::Request::UrlEncoded",
|
|
10
|
-
"Faraday::Adapter::NetHttp"
|
|
11
|
-
]
|
|
12
|
+
expect(instance.handler.builder.handlers.collect(&:name))
|
|
13
|
+
.to include("ApiClient::Connection::Middlewares::Request::OAuth", "Faraday::Request::UrlEncoded")
|
|
12
14
|
end
|
|
13
15
|
|
|
14
16
|
it "adds the logger middlewares to faraday if ApiClient.logger is available" do
|
|
15
17
|
logger = double
|
|
16
18
|
ApiClient.stub(:logger).and_return(logger)
|
|
17
19
|
instance = ApiClient::Connection::Oauth.new("http://google.com")
|
|
18
|
-
instance.handler.builder.handlers.collect(&:name)
|
|
19
|
-
"ApiClient::Connection::Middlewares::Request::Logger",
|
|
20
|
-
"ApiClient::Connection::Middlewares::Request::OAuth",
|
|
21
|
-
"Faraday::Request::UrlEncoded",
|
|
22
|
-
"Faraday::Adapter::NetHttp"
|
|
23
|
-
]
|
|
24
|
-
|
|
20
|
+
expect(instance.handler.builder.handlers.collect(&:name))
|
|
21
|
+
.to include("ApiClient::Connection::Middlewares::Request::Logger", "ApiClient::Connection::Middlewares::Request::OAuth", "Faraday::Request::UrlEncoded")
|
|
25
22
|
end
|
|
26
|
-
|
|
27
23
|
end
|
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.
|
|
4
|
+
version: 0.6.0
|
|
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: 2022-05-26 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: rspec
|
|
@@ -61,7 +61,7 @@ dependencies:
|
|
|
61
61
|
version: 0.8.1
|
|
62
62
|
- - "<"
|
|
63
63
|
- !ruby/object:Gem::Version
|
|
64
|
-
version:
|
|
64
|
+
version: 2.0.0
|
|
65
65
|
type: :runtime
|
|
66
66
|
prerelease: false
|
|
67
67
|
version_requirements: !ruby/object:Gem::Requirement
|
|
@@ -71,7 +71,7 @@ dependencies:
|
|
|
71
71
|
version: 0.8.1
|
|
72
72
|
- - "<"
|
|
73
73
|
- !ruby/object:Gem::Version
|
|
74
|
-
version:
|
|
74
|
+
version: 2.0.0
|
|
75
75
|
- !ruby/object:Gem::Dependency
|
|
76
76
|
name: multi_json
|
|
77
77
|
requirement: !ruby/object:Gem::Requirement
|
|
@@ -93,22 +93,12 @@ executables: []
|
|
|
93
93
|
extensions: []
|
|
94
94
|
extra_rdoc_files: []
|
|
95
95
|
files:
|
|
96
|
-
- ".gitignore"
|
|
97
|
-
- ".rspec"
|
|
98
|
-
- ".travis.yml"
|
|
99
96
|
- CHANGELOG.md
|
|
100
97
|
- Gemfile
|
|
101
98
|
- LICENSE
|
|
102
99
|
- Makefile
|
|
103
100
|
- README.md
|
|
104
101
|
- Rakefile
|
|
105
|
-
- api_client.gemspec
|
|
106
|
-
- examples/digg.rb
|
|
107
|
-
- examples/flickr.rb
|
|
108
|
-
- examples/github.rb
|
|
109
|
-
- examples/highrise.rb
|
|
110
|
-
- examples/twitter.rb
|
|
111
|
-
- examples/twitter_oauth.rb
|
|
112
102
|
- lib/api_client.rb
|
|
113
103
|
- lib/api_client/base.rb
|
|
114
104
|
- lib/api_client/connection/abstract.rb
|
|
@@ -164,15 +154,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
|
164
154
|
requirements:
|
|
165
155
|
- - ">="
|
|
166
156
|
- !ruby/object:Gem::Version
|
|
167
|
-
version:
|
|
157
|
+
version: 2.3.8
|
|
168
158
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
169
159
|
requirements:
|
|
170
160
|
- - ">="
|
|
171
161
|
- !ruby/object:Gem::Version
|
|
172
162
|
version: '0'
|
|
173
163
|
requirements: []
|
|
174
|
-
|
|
175
|
-
rubygems_version: 2.5.2.3
|
|
164
|
+
rubygems_version: 3.4.0.dev
|
|
176
165
|
signing_key:
|
|
177
166
|
specification_version: 3
|
|
178
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,49 +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 = ["Zendesk"]
|
|
9
|
-
s.email = ["opensource@zendesk.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
|
-
s.license = "Apache License Version 2.0"
|
|
14
|
-
|
|
15
|
-
s.rubyforge_project = "api_client"
|
|
16
|
-
|
|
17
|
-
# Declare runtime dependencies here:
|
|
18
|
-
def s.add_runtime_dependencies(method)
|
|
19
|
-
if RUBY_PLATFORM == "java"
|
|
20
|
-
send method, 'jrjackson'
|
|
21
|
-
else
|
|
22
|
-
send method, 'yajl-ruby'
|
|
23
|
-
end
|
|
24
|
-
|
|
25
|
-
send method, 'hashie', [">= 2.0.5"]
|
|
26
|
-
send method, 'faraday', [">= 0.8.1", "< 1.0.0"]
|
|
27
|
-
send method, 'multi_json', [">= 1.6.1"]
|
|
28
|
-
end
|
|
29
|
-
|
|
30
|
-
# Declare development dependencies here:
|
|
31
|
-
s.add_development_dependency 'rspec', '2.14.1'
|
|
32
|
-
|
|
33
|
-
if s.respond_to? :specification_version then
|
|
34
|
-
s.specification_version = 3
|
|
35
|
-
|
|
36
|
-
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
|
37
|
-
s.add_runtime_dependencies(:add_runtime_dependency)
|
|
38
|
-
else
|
|
39
|
-
s.add_runtime_dependencies(:add_dependency)
|
|
40
|
-
end
|
|
41
|
-
else
|
|
42
|
-
s.add_runtime_dependencies(:add_dependency)
|
|
43
|
-
end
|
|
44
|
-
|
|
45
|
-
s.files = `git ls-files`.split("\n")
|
|
46
|
-
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
|
47
|
-
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
|
48
|
-
s.require_paths = ["lib"]
|
|
49
|
-
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
|