twitter_api 0.1.1 → 0.1.2
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/README.md +5 -9
- data/lib/twitter_api.rb +80 -33
- data/lib/twitter_api/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 43a114e1feb00e8dd32a91acbd0903359e89d87d
|
4
|
+
data.tar.gz: f703b82e78be5ded9331bcc92cb6d269d4f4a5f5
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3be34676bc85d29da9741dafd1241ab8e392a8c5d367f4365d5259de5db9c5e9e8045635c663493eca42472d24ddb5aa23e68eb90dfe18cc332c22b23a937910
|
7
|
+
data.tar.gz: f7a3be2567eab539b68fa9d5115506023f98e2d97b4596f0b264041e305523ca7ad172959656baa29fc927e8bd595cbae73e8f085b5a6ed7ca54958c90aea5cd
|
data/README.md
CHANGED
@@ -34,7 +34,7 @@ t = TwitterAPI::Client.new({
|
|
34
34
|
|
35
35
|
# call GET statuses/user_timeline
|
36
36
|
res = t.get('https://api.twitter.com/1.1/statuses/user_timeline.json', {
|
37
|
-
'screen_name' => '
|
37
|
+
'screen_name' => 'YOUR_SCREEN_NAME',
|
38
38
|
'count' => '1'
|
39
39
|
})
|
40
40
|
puts res.headers
|
@@ -42,7 +42,7 @@ puts JSON.pretty_generate(JSON.parse(res.body))
|
|
42
42
|
|
43
43
|
# call GET statuses/user_timeline
|
44
44
|
res = t.statuses_user_timeline({
|
45
|
-
'screen_name' => '
|
45
|
+
'screen_name' => 'YOUR_SCREEN_NAME',
|
46
46
|
'count' => '1'
|
47
47
|
})
|
48
48
|
puts res.headers
|
@@ -61,17 +61,13 @@ res = t.statuses_update({
|
|
61
61
|
})
|
62
62
|
puts res.headers
|
63
63
|
puts JSON.pretty_generate(JSON.parse(res.body))
|
64
|
-
|
65
|
-
# call GET statues/mention_timeline
|
66
|
-
res = t.statuses_mentions_timeline({
|
67
|
-
'count' => '1'
|
68
|
-
})
|
69
|
-
puts res.headers
|
70
|
-
puts JSON.pretty_generate(JSON.parse(res.body))
|
71
64
|
```
|
72
65
|
|
73
66
|
## Documentation
|
74
67
|
|
68
|
+
Documentation for twitter_api
|
69
|
+
http://www.rubydoc.info/gems/twitter_api/
|
70
|
+
|
75
71
|
Reference Documentation — Twitter Developers
|
76
72
|
https://dev.twitter.com/rest/reference
|
77
73
|
|
data/lib/twitter_api.rb
CHANGED
@@ -5,30 +5,41 @@ require 'open-uri'
|
|
5
5
|
require 'simple_oauth'
|
6
6
|
|
7
7
|
# Twitter API Ruby thin client wrapper library
|
8
|
+
# {https://github.com/niwasawa/twitter-api-ruby-thin-client-wrapper}
|
8
9
|
module TwitterAPI
|
9
10
|
|
11
|
+
# A client class.
|
10
12
|
class Client
|
11
13
|
|
14
|
+
# Initializes a Client object.
|
15
|
+
#
|
16
|
+
# @param credentials [Hash] Credentials
|
17
|
+
# @return [TwitterAPI::Client]
|
12
18
|
def initialize(credentials)
|
13
19
|
@credentials = credentials
|
14
20
|
end
|
15
21
|
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
# @return
|
21
|
-
def get(
|
22
|
-
headers = {'Authorization' => authorization('GET',
|
23
|
-
url =
|
22
|
+
# Calls a Twitter REST API using GET method.
|
23
|
+
#
|
24
|
+
# @param resource_url [String] Resource URL
|
25
|
+
# @param params [Hash] Parameters
|
26
|
+
# @return [TwitterAPI::Response]
|
27
|
+
def get(resource_url, params)
|
28
|
+
headers = {'Authorization' => authorization('GET', resource_url, params)}
|
29
|
+
url = resource_url + '?' + URI.encode_www_form(params)
|
24
30
|
res = open(url, headers)
|
25
31
|
Response.new(res)
|
26
32
|
end
|
27
33
|
|
28
|
-
#
|
29
|
-
|
30
|
-
|
31
|
-
|
34
|
+
# Calls a Twitter REST API using POST method.
|
35
|
+
#
|
36
|
+
# @param resource_url [String] Resource URL
|
37
|
+
# @param params [Hash] Parameters
|
38
|
+
# @param data [String] Posts data
|
39
|
+
# @return [TwitterAPI::Response]
|
40
|
+
def post(resource_url, params, data=nil)
|
41
|
+
headers = {'Authorization' => authorization('POST', resource_url, params)}
|
42
|
+
url = resource_url + '?' + URI.encode_www_form(params)
|
32
43
|
uri = URI.parse(url)
|
33
44
|
http = Net::HTTP.new(uri.host, uri.port)
|
34
45
|
http.use_ssl = true
|
@@ -37,55 +48,91 @@ module TwitterAPI
|
|
37
48
|
Response.new(res)
|
38
49
|
end
|
39
50
|
|
40
|
-
# GET search/tweets
|
41
|
-
# https://dev.twitter.com/rest/reference/get/search/tweets
|
51
|
+
# GET search/tweets
|
52
|
+
# {https://dev.twitter.com/rest/reference/get/search/tweets}
|
53
|
+
#
|
54
|
+
# @param params [Hash] Parameters
|
55
|
+
# @return [TwitterAPI::Response]
|
42
56
|
def search_tweets(params)
|
43
|
-
|
44
|
-
get(
|
57
|
+
resource_url = 'https://api.twitter.com/1.1/search/tweets.json'
|
58
|
+
get(resource_url, params)
|
45
59
|
end
|
46
60
|
|
47
|
-
# GET statuses/mentions_timeline
|
48
|
-
# https://dev.twitter.com/rest/reference/get/statuses/mentions_timeline
|
61
|
+
# GET statuses/mentions_timeline
|
62
|
+
# {https://dev.twitter.com/rest/reference/get/statuses/mentions_timeline}
|
63
|
+
#
|
64
|
+
# @param params [Hash] Parameters
|
65
|
+
# @return [TwitterAPI::Response]
|
49
66
|
def statuses_mentions_timeline(params)
|
50
|
-
|
51
|
-
get(
|
67
|
+
resource_url = 'https://api.twitter.com/1.1/statuses/mentions_timeline.json'
|
68
|
+
get(resource_url, params)
|
52
69
|
end
|
53
70
|
|
54
|
-
# GET statuses/user_timeline
|
55
|
-
# https://dev.twitter.com/rest/reference/get/statuses/user_timeline
|
71
|
+
# GET statuses/user_timeline
|
72
|
+
# {https://dev.twitter.com/rest/reference/get/statuses/user_timeline}
|
73
|
+
#
|
74
|
+
# @param params [Hash] Parameters
|
75
|
+
# @return [TwitterAPI::Response]
|
56
76
|
def statuses_user_timeline(params)
|
57
|
-
|
58
|
-
get(
|
77
|
+
resource_url = 'https://api.twitter.com/1.1/statuses/user_timeline.json'
|
78
|
+
get(resource_url, params)
|
59
79
|
end
|
60
80
|
|
61
|
-
# POST statuses/update
|
62
|
-
# https://dev.twitter.com/rest/reference/post/statuses/update
|
81
|
+
# POST statuses/update
|
82
|
+
# {https://dev.twitter.com/rest/reference/post/statuses/update}
|
83
|
+
#
|
84
|
+
# @param params [Hash] Parameters
|
85
|
+
# @return [TwitterAPI::Response]
|
63
86
|
def statuses_update(params)
|
64
|
-
|
65
|
-
post(
|
87
|
+
resource_url = 'https://api.twitter.com/1.1/statuses/update.json'
|
88
|
+
post(resource_url, params)
|
89
|
+
end
|
90
|
+
|
91
|
+
private
|
92
|
+
|
93
|
+
# Returns string of authorization.
|
94
|
+
#
|
95
|
+
# @param method [String] A HTTP method
|
96
|
+
# @param url [String] A URL
|
97
|
+
# @param params [Hash] Parameters
|
98
|
+
# @return [String]
|
99
|
+
def authorization(method, url, params)
|
100
|
+
SimpleOAuth::Header.new(method, url, params, @credentials).to_s
|
66
101
|
end
|
102
|
+
|
67
103
|
end
|
68
104
|
|
105
|
+
# A HTTP Response class.
|
69
106
|
class Response
|
70
107
|
|
108
|
+
# Initializes a Response object.
|
109
|
+
#
|
110
|
+
# @param res [StringIO]
|
111
|
+
# @param res [Tempfile]
|
112
|
+
# @return [TwitterAPI::Client]
|
71
113
|
def initialize(res)
|
72
114
|
@res = res
|
73
115
|
end
|
74
116
|
|
75
|
-
#
|
117
|
+
# Returns HTTP headers.
|
118
|
+
#
|
119
|
+
# @return [Net::HTTPHeader]
|
120
|
+
# @return [Hash]
|
76
121
|
def headers
|
77
122
|
if @res.kind_of?(Net::HTTPResponse)
|
78
|
-
@res
|
123
|
+
@res # Net::HTTPHeader
|
79
124
|
elsif @res.kind_of?(StringIO)
|
80
|
-
@res.meta
|
125
|
+
@res.meta # Hash
|
81
126
|
elsif @res.kind_of?(Tempfile)
|
82
|
-
@res.meta
|
127
|
+
@res.meta # Hash
|
83
128
|
else
|
84
129
|
nil
|
85
130
|
end
|
86
131
|
end
|
87
132
|
|
88
|
-
#
|
133
|
+
# Returns HTTP body.
|
134
|
+
#
|
135
|
+
# @return [String]
|
89
136
|
def body
|
90
137
|
if @res.kind_of?(Net::HTTPResponse)
|
91
138
|
@res.body
|
data/lib/twitter_api/version.rb
CHANGED