twitter_api 0.1.4 → 0.1.5
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 +4 -4
- data/lib/twitter_api.rb +128 -16
- data/lib/twitter_api/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 687522614099fad8793bf736f27656511b23f6f9
|
4
|
+
data.tar.gz: 1ab167f48de4390e4cc094ba6e64f705cee7867e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: dd9415e903be0cf2dbc90b8225536ca52791e12c5a1b49fbc7960acd0224b9b3c6a2c8723e7bba103183f8472735c53a347775062842f29a002dc438809261f4
|
7
|
+
data.tar.gz: '02295227407b49e5d3d651075cfa270a64ce1a909704ffcd28c67487ce29fc3cbec9e1cf21d5560c7ac400fceccfe33a08083e4b01fc50868cf223694890b520'
|
data/lib/twitter_api.rb
CHANGED
@@ -9,15 +9,94 @@ require 'tempfile'
|
|
9
9
|
# {https://github.com/niwasawa/twitter-api-ruby-thin-client-wrapper}
|
10
10
|
module TwitterAPI
|
11
11
|
|
12
|
+
# A base client class.
|
13
|
+
class BaseClient
|
14
|
+
|
15
|
+
# Initializes a BaseClient object.
|
16
|
+
#
|
17
|
+
# @param credentials [Hash] Credentials
|
18
|
+
# @return [TwitterAPI::BaseClient]
|
19
|
+
def initialize(credentials)
|
20
|
+
@credentials = credentials
|
21
|
+
end
|
22
|
+
|
23
|
+
# Calls a Twitter REST API using GET method.
|
24
|
+
#
|
25
|
+
# @param resource_url [String] Resource URL
|
26
|
+
# @param params [Hash] Parameters
|
27
|
+
# @return [TwitterAPI::Response]
|
28
|
+
def get(resource_url, params)
|
29
|
+
headers = {'Authorization' => authorization('GET', resource_url, params)}
|
30
|
+
url = resource_url + '?' + URI.encode_www_form(params)
|
31
|
+
res = open(url, headers)
|
32
|
+
Response.new(res)
|
33
|
+
end
|
34
|
+
|
35
|
+
# Calls a Twitter REST API using POST method.
|
36
|
+
#
|
37
|
+
# @param resource_url [String] Resource URL
|
38
|
+
# @param params [Hash] Parameters
|
39
|
+
# @param data [String] Posts data
|
40
|
+
# @return [TwitterAPI::Response]
|
41
|
+
def post(resource_url, params, data=nil)
|
42
|
+
headers = {'Authorization' => authorization('POST', resource_url, params)}
|
43
|
+
url = resource_url + '?' + URI.encode_www_form(params)
|
44
|
+
uri = URI.parse(url)
|
45
|
+
http = Net::HTTP.new(uri.host, uri.port)
|
46
|
+
http.use_ssl = true
|
47
|
+
http.verify_mode = OpenSSL::SSL::VERIFY_NONE
|
48
|
+
res = http.request_post(url, data, headers)
|
49
|
+
Response.new(res)
|
50
|
+
end
|
51
|
+
|
52
|
+
# Calls a Twitter REST API using POST (multipart/form-data) method.
|
53
|
+
#
|
54
|
+
# @param resource_url [String] Resource URL
|
55
|
+
# @param params [Hash] Parameters
|
56
|
+
# @param data [Array] Posts Multipart data
|
57
|
+
# @return [TwitterAPI::Response]
|
58
|
+
def post_multipart(resource_url, params, data={})
|
59
|
+
headers = {'Authorization' => authorization('POST', resource_url, params)}
|
60
|
+
url = resource_url + '?' + URI.encode_www_form(params)
|
61
|
+
uri = URI.parse(url)
|
62
|
+
form_data = []
|
63
|
+
data.each{|k,v|
|
64
|
+
form_data << [k,v]
|
65
|
+
}
|
66
|
+
http = Net::HTTP.new(uri.host, uri.port)
|
67
|
+
http.use_ssl = true
|
68
|
+
http.verify_mode = OpenSSL::SSL::VERIFY_NONE
|
69
|
+
req = Net::HTTP::Post.new(uri.request_uri, headers)
|
70
|
+
req.set_form(form_data, 'multipart/form-data')
|
71
|
+
res = http.start{|h|
|
72
|
+
h.request(req)
|
73
|
+
}
|
74
|
+
Response.new(res)
|
75
|
+
end
|
76
|
+
|
77
|
+
private
|
78
|
+
|
79
|
+
# Returns string of authorization.
|
80
|
+
#
|
81
|
+
# @param method [String] A HTTP method
|
82
|
+
# @param url [String] A URL
|
83
|
+
# @param params [Hash] Parameters
|
84
|
+
# @return [String]
|
85
|
+
def authorization(method, url, params)
|
86
|
+
SimpleOAuth::Header.new(method, url, params, @credentials).to_s
|
87
|
+
end
|
88
|
+
|
89
|
+
end
|
90
|
+
|
12
91
|
# A client class.
|
13
|
-
class Client
|
92
|
+
class Client < BaseClient
|
14
93
|
|
15
94
|
# Initializes a Client object.
|
16
95
|
#
|
17
96
|
# @param credentials [Hash] Credentials
|
18
97
|
# @return [TwitterAPI::Client]
|
19
98
|
def initialize(credentials)
|
20
|
-
|
99
|
+
super
|
21
100
|
end
|
22
101
|
|
23
102
|
# Calls a Twitter REST API using GET method.
|
@@ -49,6 +128,31 @@ module TwitterAPI
|
|
49
128
|
Response.new(res)
|
50
129
|
end
|
51
130
|
|
131
|
+
# Calls a Twitter REST API using POST (multipart/form-data) method.
|
132
|
+
#
|
133
|
+
# @param resource_url [String] Resource URL
|
134
|
+
# @param params [Hash] Parameters
|
135
|
+
# @param data [Array] Posts Multipart data
|
136
|
+
# @return [TwitterAPI::Response]
|
137
|
+
def post_multipart(resource_url, params, data={})
|
138
|
+
headers = {'Authorization' => authorization('POST', resource_url, params)}
|
139
|
+
url = resource_url + '?' + URI.encode_www_form(params)
|
140
|
+
uri = URI.parse(url)
|
141
|
+
form_data = []
|
142
|
+
data.each{|k,v|
|
143
|
+
form_data << [k,v]
|
144
|
+
}
|
145
|
+
http = Net::HTTP.new(uri.host, uri.port)
|
146
|
+
http.use_ssl = true
|
147
|
+
http.verify_mode = OpenSSL::SSL::VERIFY_NONE
|
148
|
+
req = Net::HTTP::Post.new(uri.request_uri, headers)
|
149
|
+
req.set_form(form_data, 'multipart/form-data')
|
150
|
+
res = http.start{|h|
|
151
|
+
h.request(req)
|
152
|
+
}
|
153
|
+
Response.new(res)
|
154
|
+
end
|
155
|
+
|
52
156
|
# GET geo/id/:place_id
|
53
157
|
# {https://dev.twitter.com/rest/reference/get/geo/id/place_id}
|
54
158
|
#
|
@@ -99,26 +203,34 @@ module TwitterAPI
|
|
99
203
|
get(resource_url, params)
|
100
204
|
end
|
101
205
|
|
102
|
-
#
|
103
|
-
# {https://dev.twitter.com/rest/reference/
|
206
|
+
# GET users/lookup
|
207
|
+
# {https://dev.twitter.com/rest/reference/get/users/lookup}
|
104
208
|
#
|
105
209
|
# @param params [Hash] Parameters
|
106
210
|
# @return [TwitterAPI::Response]
|
107
|
-
def
|
108
|
-
resource_url = 'https://api.twitter.com/1.1/
|
109
|
-
|
211
|
+
def users_lookup(params)
|
212
|
+
resource_url = 'https://api.twitter.com/1.1/users/lookup.json'
|
213
|
+
get(resource_url, params)
|
110
214
|
end
|
111
215
|
|
112
|
-
|
216
|
+
# POST media/upload
|
217
|
+
# {https://dev.twitter.com/rest/reference/post/media/upload}
|
218
|
+
#
|
219
|
+
# @param params [Hash] Parameters
|
220
|
+
# @return [TwitterAPI::Response]
|
221
|
+
def media_upload(params)
|
222
|
+
resource_url = 'https://upload.twitter.com/1.1/media/upload.json'
|
223
|
+
post_multipart(resource_url, {}, params)
|
224
|
+
end
|
113
225
|
|
114
|
-
#
|
226
|
+
# POST statuses/update
|
227
|
+
# {https://dev.twitter.com/rest/reference/post/statuses/update}
|
115
228
|
#
|
116
|
-
# @param method [String] A HTTP method
|
117
|
-
# @param url [String] A URL
|
118
229
|
# @param params [Hash] Parameters
|
119
|
-
# @return [
|
120
|
-
def
|
121
|
-
|
230
|
+
# @return [TwitterAPI::Response]
|
231
|
+
def statuses_update(params)
|
232
|
+
resource_url = 'https://api.twitter.com/1.1/statuses/update.json'
|
233
|
+
post(resource_url, params)
|
122
234
|
end
|
123
235
|
|
124
236
|
end
|
@@ -130,7 +242,7 @@ module TwitterAPI
|
|
130
242
|
#
|
131
243
|
# @param res [StringIO]
|
132
244
|
# @param res [Tempfile]
|
133
|
-
# @return [TwitterAPI::
|
245
|
+
# @return [TwitterAPI::Response]
|
134
246
|
def initialize(res)
|
135
247
|
@res = res
|
136
248
|
@headers = make_headers
|
@@ -153,7 +265,7 @@ module TwitterAPI
|
|
153
265
|
end
|
154
266
|
|
155
267
|
private
|
156
|
-
|
268
|
+
|
157
269
|
# Returns HTTP headers.
|
158
270
|
#
|
159
271
|
# @return [Net::HTTPHeader]
|
data/lib/twitter_api/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: twitter_api
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Naoki Iwasawa
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-03-
|
11
|
+
date: 2017-03-29 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: simple_oauth
|