oauth_twitter 0.1.0 → 0.2.1
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 +8 -8
- data/README.md +48 -13
- data/lib/oauth_twitter/api/friends.rb +93 -7
- data/lib/oauth_twitter/api/oauth.rb +27 -10
- data/lib/oauth_twitter/api/statuses.rb +74 -12
- data/lib/oauth_twitter/api/users.rb +64 -13
- data/lib/oauth_twitter/helper.rb +48 -21
- data/lib/oauth_twitter/version.rb +1 -1
- data/oauth_twitter.gemspec +3 -3
- metadata +7 -5
checksums.yaml
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
---
|
2
2
|
!binary "U0hBMQ==":
|
3
3
|
metadata.gz: !binary |-
|
4
|
-
|
4
|
+
MjJkZWU1ZGM2YjFmNjUyNWRhNGYzN2E1OTI3ODNkYjRhNDU4MDBkYg==
|
5
5
|
data.tar.gz: !binary |-
|
6
|
-
|
6
|
+
OTgzMjA3Zjk2YWMzNjUxYzIzYTRmODM4NjA2NWM1YzJlYjZkM2RlOA==
|
7
7
|
!binary "U0hBNTEy":
|
8
8
|
metadata.gz: !binary |-
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
YzA5YzM5NjUxMDYxZDRkNDU2YjRmZTYzY2FjMGQ2MGQ5ZGEwZGYxMGEwODA4
|
10
|
+
MmQ3MTY0Zjg4ODQ2YzE1ZDcxMDViMDBjY2MzNjIzMWFlZmM3ZGFjNjUzMTA5
|
11
|
+
MjljNmQxZGE2OTdkYTU0OThkOGRhNWFiODI1YTI4OTIzMGE3Y2I=
|
12
12
|
data.tar.gz: !binary |-
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
NjI0MDE3NDczYzAzMDJkZDczNTE0N2RlODY5Y2YzOTA5OWFlZjE4ZjM1ZDI4
|
14
|
+
YWFkNmZhYjg3N2Q1NDkwZDU0Njk2M2Y3YjNmMGIxOTI5MjlkNGNlNTlmMDkz
|
15
|
+
NDA4OTViMjBhMGEyOGFlN2Y4MDllMjI4ZTc4MDdmODc4ZjcxNzI=
|
data/README.md
CHANGED
@@ -1,29 +1,64 @@
|
|
1
1
|
# OauthTwitter
|
2
2
|
|
3
|
-
|
3
|
+
An OAuth library to interact with Twitter API v1.1, by simply calling methods on instances. The methods name is designed to be similar to Twitter's API. For example:
|
4
4
|
|
5
|
-
|
5
|
+
If you want to load home timeline for certain user, just do:
|
6
|
+
|
7
|
+
response = your_instance.home_timeline
|
8
|
+
response.each {|r| process_response(r)}
|
9
|
+
|
10
|
+
The response is a nested hash that structured the same as Twitter's response JSON.
|
11
|
+
|
12
|
+
## 1. Installation
|
6
13
|
|
7
14
|
Add this line to your application's Gemfile:
|
8
15
|
|
9
16
|
gem 'oauth_twitter'
|
10
17
|
|
11
|
-
|
18
|
+
Then execute:
|
12
19
|
|
13
|
-
$ bundle
|
20
|
+
$ bundle install
|
14
21
|
|
15
|
-
Or install it yourself
|
22
|
+
Or install it yourself use:
|
16
23
|
|
17
24
|
$ gem install oauth_twitter
|
25
|
+
|
26
|
+
## 2. Setup and Usage
|
27
|
+
|
28
|
+
1) Configure __OauthTwitter__ on app initialization:
|
29
|
+
|
30
|
+
OauthTwitter::Config.setup do |c|
|
31
|
+
c.consumer_key = "#{your_twitter_consumer_key}"
|
32
|
+
c.consumer_secret = "#{twitter_consumer_secret}"
|
33
|
+
|
34
|
+
# Your don't have to include following in your initializer,
|
35
|
+
# but OauthTwitter will fallback to this url
|
36
|
+
# if you don't provide them in certain functions' args
|
37
|
+
|
38
|
+
c.oauth_callback = "#{oauth_request_token_callback_address}"
|
39
|
+
end
|
40
|
+
|
41
|
+
2) Include `OauthTwitter` in your class like:
|
42
|
+
|
43
|
+
class YouClass
|
44
|
+
include OauthTwitter
|
45
|
+
…
|
46
|
+
end
|
47
|
+
|
48
|
+
3) Implement `attr_accessor` in your class, so __OauthTwitter__ could load tokens from `YourClass`:
|
49
|
+
|
50
|
+
class YourClass
|
51
|
+
include OauthTwitter
|
52
|
+
|
53
|
+
attr_accessor :oauth_token, :oauth_token_secret
|
54
|
+
...
|
55
|
+
end
|
18
56
|
|
19
|
-
|
57
|
+
4) You can start calling methods on `YourClass`:
|
20
58
|
|
21
|
-
|
59
|
+
you_instance = YourClass.new
|
60
|
+
you_instance.request_token("callback_url")
|
22
61
|
|
23
|
-
##
|
62
|
+
## Documentation
|
24
63
|
|
25
|
-
|
26
|
-
2. Create your feature branch (`git checkout -b my-new-feature`)
|
27
|
-
3. Commit your changes (`git commit -am 'Add some feature'`)
|
28
|
-
4. Push to the branch (`git push origin my-new-feature`)
|
29
|
-
5. Create new Pull Request
|
64
|
+
Still a work in process...
|
@@ -2,16 +2,102 @@ module OauthTwitter
|
|
2
2
|
module API
|
3
3
|
module Friends
|
4
4
|
PATH = {
|
5
|
-
|
5
|
+
:friendships_no_retweets_ids => '/1.1/friendships/no_retweets/ids.json',
|
6
|
+
:friends_ids => '/1.1/friends/ids.json',
|
7
|
+
:followers_ids => '/1.1/followers/ids.json',
|
8
|
+
:friendships_lookup => '/1.1/friendships/lookup.json',
|
9
|
+
:friendships_incoming => '/1.1/friendships/incoming.json',
|
10
|
+
:friendships_outgoing => '/1.1/friendships/outgoing.json',
|
11
|
+
:friendships_create => '/1.1/friendships/create.json',
|
12
|
+
:friendships_destroy => '/1.1/friendships/destroy.json',
|
13
|
+
:friendships_update => '/1.1/friendships/update.json',
|
14
|
+
:friendships_show => '/1.1/friendships/show.json',
|
15
|
+
:friends_list => '/1.1/friends/list.json',
|
16
|
+
:followers_list => '/1.1/followers/list.json'
|
6
17
|
}
|
7
18
|
|
8
|
-
def
|
19
|
+
def friendships_no_retweets_ids(params={}, options={})
|
20
|
+
query = params.clone
|
9
21
|
oauth = oauth_params(true)
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
22
|
+
response = send_request(:GET, PATH[:friendships_no_retweets_ids], query, oauth)
|
23
|
+
return results_with_error_explained(response, options)
|
24
|
+
end
|
25
|
+
|
26
|
+
def friends_ids(params={}, options={})
|
27
|
+
query = params.clone
|
28
|
+
oauth = oauth_params(true)
|
29
|
+
response = send_request(:GET, PATH[:friends_ids], query, oauth)
|
30
|
+
return results_with_error_explained(response, options)
|
31
|
+
end
|
32
|
+
|
33
|
+
def followers_ids(params={}, options={})
|
34
|
+
query = params.clone
|
35
|
+
oauth = oauth_params(true)
|
36
|
+
response = send_request(:GET, PATH[:followers_ids], query, oauth)
|
37
|
+
return results_with_error_explained(response, options)
|
38
|
+
end
|
39
|
+
|
40
|
+
def friendships_lookup(params={}, options={})
|
41
|
+
query = params.clone
|
42
|
+
oauth = oauth_params(true)
|
43
|
+
response = send_request(:GET, PATH[:friendships_lookup], query, oauth)
|
44
|
+
return results_with_error_explained(response, options)
|
45
|
+
end
|
46
|
+
|
47
|
+
def friendships_incoming(params={}, options={})
|
48
|
+
query = params.clone
|
49
|
+
oauth = oauth_params(true)
|
50
|
+
response = send_request(:GET, PATH[:friendships_incoming], query, oauth)
|
51
|
+
return results_with_error_explained(response, options)
|
52
|
+
end
|
53
|
+
|
54
|
+
def friendships_outgoing(params={}, options={})
|
55
|
+
query = params.clone
|
56
|
+
oauth = oauth_params(true)
|
57
|
+
response = send_request(:GET, PATH[:friendships_outgoing], query, oauth)
|
58
|
+
return results_with_error_explained(response, options)
|
59
|
+
end
|
60
|
+
|
61
|
+
def friendships_create(params={}, options={})
|
62
|
+
query = params.clone
|
63
|
+
oauth = oauth_params(true)
|
64
|
+
response = send_request(:POST, PATH[:friendships_create], query, oauth)
|
65
|
+
return results_with_error_explained(response, options)
|
66
|
+
end
|
67
|
+
|
68
|
+
def friendships_destroy(params={}, options={})
|
69
|
+
query = params.clone
|
70
|
+
oauth = oauth_params(true)
|
71
|
+
response = send_request(:POST, PATH[:friendships_destroy], query, oauth)
|
72
|
+
return results_with_error_explained(response, options)
|
73
|
+
end
|
74
|
+
|
75
|
+
def friendships_update(params={}, options={})
|
76
|
+
query = params.clone
|
77
|
+
oauth = oauth_params(true)
|
78
|
+
response = send_request(:POST, PATH[:friendships_update], query, oauth)
|
79
|
+
return results_with_error_explained(response, options)
|
80
|
+
end
|
81
|
+
|
82
|
+
def friendships_show(params={}, options={})
|
83
|
+
query = params.clone
|
84
|
+
oauth = oauth_params(true)
|
85
|
+
response = send_request(:GET, PATH[:friendships_show], query, oauth)
|
86
|
+
return results_with_error_explained(response, options)
|
87
|
+
end
|
88
|
+
|
89
|
+
def friends_list(params={}, options={})
|
90
|
+
query = params.clone
|
91
|
+
oauth = oauth_params(true)
|
92
|
+
response = send_request(:GET, PATH[:friends_list], query, oauth)
|
93
|
+
return results_with_error_explained(response, options)
|
94
|
+
end
|
95
|
+
|
96
|
+
def followers_list(params={}, options={})
|
97
|
+
query = params.clone
|
98
|
+
oauth = oauth_params(true)
|
99
|
+
response = send_request(:GET, PATH[:followers_list], query, oauth)
|
100
|
+
return results_with_error_explained(response, options)
|
15
101
|
end
|
16
102
|
|
17
103
|
end
|
@@ -2,21 +2,38 @@ module OauthTwitter
|
|
2
2
|
module API
|
3
3
|
module Oauth
|
4
4
|
PATH = {
|
5
|
-
|
6
|
-
|
5
|
+
:oauth_authenticate => '/oauth/authenticate',
|
6
|
+
:oauth_authorize => '/oauth/authorize',
|
7
|
+
:oauth_access_token => '/oauth/access_token',
|
8
|
+
:oauth_request_token => '/oauth/request_token'
|
7
9
|
}
|
8
10
|
|
9
|
-
def
|
10
|
-
|
11
|
-
oauth = oauth_params(
|
12
|
-
|
13
|
-
|
14
|
-
|
11
|
+
def oauth_authenticate(params={}, options={})
|
12
|
+
query = params.clone
|
13
|
+
oauth = oauth_params(true)
|
14
|
+
response = send_request(:GET, PATH[:oauth_authenticate], query, oauth)
|
15
|
+
return results_with_error_explained(response, options)
|
16
|
+
end
|
17
|
+
|
18
|
+
def oauth_authorize(params={}, options={})
|
19
|
+
query = params.clone
|
20
|
+
oauth = oauth_params(true)
|
21
|
+
response = send_request(:GET, PATH[:oauth_authorize], query, oauth)
|
22
|
+
return results_with_error_explained(response, options)
|
15
23
|
end
|
16
24
|
|
17
|
-
def
|
25
|
+
def oauth_access_token(params={}, options={})
|
26
|
+
query = params.clone
|
18
27
|
oauth = oauth_params(true)
|
19
|
-
|
28
|
+
response = send_request(:POST, PATH[:oauth_access_token], query, oauth)
|
29
|
+
return results_with_error_explained(response, options)
|
30
|
+
end
|
31
|
+
|
32
|
+
def oauth_request_token(params={}, options={})
|
33
|
+
callback_url = params[:oauth_callback] || Config.oauth_callback
|
34
|
+
oauth = oauth_params(false, {oauth_callback: callback_url})
|
35
|
+
response = send_request(:POST, PATH[:oauth_request_token], nil, oauth)
|
36
|
+
return results_with_error_explained(response, options)
|
20
37
|
end
|
21
38
|
|
22
39
|
end
|
@@ -1,21 +1,83 @@
|
|
1
1
|
module OauthTwitter
|
2
2
|
module API
|
3
3
|
module Statuses
|
4
|
+
|
5
|
+
##
|
6
|
+
# Url path of status API
|
4
7
|
PATH = {
|
5
|
-
|
8
|
+
:mentions_timeline => '/1.1/statuses/mentions_timeline.json',
|
9
|
+
:user_timeline => '/1.1/statuses/user_timeline.json',
|
10
|
+
:home_timeline => '/1.1/statuses/home_timeline.json',
|
11
|
+
:retweets_of_me => '/1.1/statuses/retweets_of_me.json'
|
6
12
|
}
|
7
13
|
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
14
|
+
##
|
15
|
+
# Load current user's Tweet with @user_name mentioned, include user
|
16
|
+
# mention themselves.
|
17
|
+
#
|
18
|
+
# @param params [Hash] always supply a user_id or screen_name. If both
|
19
|
+
# are supplied, user_id will be used
|
20
|
+
# @param options [Hash]
|
21
|
+
#
|
22
|
+
# @return [Array]
|
23
|
+
def mentions_timeline(params={}, options={})
|
24
|
+
query = params.clone
|
25
|
+
return send_status_request(:mentions_timeline, query, options)
|
26
|
+
end
|
27
|
+
|
28
|
+
##
|
29
|
+
#
|
30
|
+
def user_timeline(params={}, options={})
|
31
|
+
query = params.clone
|
32
|
+
return send_status_request(:user_timeline, query, options)
|
33
|
+
end
|
34
|
+
|
35
|
+
##
|
36
|
+
# Load current use's (determined by oauth_token and oauth_token_secret
|
37
|
+
# variables) home time.
|
38
|
+
#
|
39
|
+
# @param params [Hash] parameters that consistent with Twitter's API.
|
40
|
+
# @param options [Hash] options to perform more operations.
|
41
|
+
#
|
42
|
+
# :pages => [Int] indicate many pages will return, for example,
|
43
|
+
# if count = 5, pages = 3, then it will return 5 * 3 = 15 tweets
|
44
|
+
# from the user's timeline. Cursor stops if response no more reponse.
|
45
|
+
#
|
46
|
+
# :explain_error => [Bool] if true, will return a HTTP Code indicate
|
47
|
+
# the error
|
48
|
+
#
|
49
|
+
# @return [Array] hash structured the same as Twitter's JSON response.
|
50
|
+
#
|
51
|
+
# if :explain_error => true, will return array like:
|
52
|
+
# [json, response.body, response.code]
|
53
|
+
def home_timeline(params={}, options={})
|
54
|
+
query = params.clone
|
55
|
+
return send_status_request(:home_timeline, query, options)
|
56
|
+
end
|
57
|
+
|
58
|
+
##
|
59
|
+
#
|
60
|
+
def retweets_of_me(params={}, options={})
|
61
|
+
query = params.clone
|
62
|
+
return send_status_request(:retweets_of_me, query, options)
|
63
|
+
end
|
64
|
+
|
65
|
+
private
|
66
|
+
##
|
67
|
+
# Private helper for each of the status API
|
68
|
+
def send_status_request(api_symbol, query, options)
|
69
|
+
full_response = []
|
70
|
+
response = nil
|
71
|
+
options[:pages] ||= 1
|
72
|
+
options[:pages].times do |page_num|
|
73
|
+
oauth = oauth_params(true)
|
74
|
+
response = send_request(:GET, PATH[api_symbol], query, oauth)
|
75
|
+
break unless response[0]
|
76
|
+
break if response[1].empty?
|
77
|
+
full_response += response[1]
|
78
|
+
query[:max_id] = response[1].last['id'] - 1
|
79
|
+
end
|
80
|
+
return results_with_error_explained(response, options, full_response)
|
19
81
|
end
|
20
82
|
|
21
83
|
end
|
@@ -2,26 +2,77 @@ module OauthTwitter
|
|
2
2
|
module API
|
3
3
|
module Users
|
4
4
|
PATH = {
|
5
|
-
users_lookup
|
5
|
+
:users_lookup => '/1.1/users/lookup.json',
|
6
|
+
:users_show => '/1.1/users/show.json',
|
7
|
+
:users_search => '/1.1/users/search.json',
|
8
|
+
:users_contributees => '/1.1/users/contributees.json',
|
9
|
+
:users_contributors => '/1.1/users/contributors.json',
|
10
|
+
:users_profile_banner => '/1.1/users/profile_banner.json'
|
6
11
|
}
|
7
12
|
|
8
|
-
|
9
|
-
|
13
|
+
##
|
14
|
+
# @param params [Hash] :screen_name => Array, :user_id => Array,
|
15
|
+
# :include_entities => Boolean
|
16
|
+
def users_lookup(params, options={})
|
17
|
+
query = params.clone
|
18
|
+
users_array = query[:screen_name] || query[:user_id]
|
19
|
+
users_array_type = (query[:screen_name]) ? :screen_name : :user_id
|
10
20
|
# slice id_array for multiple request
|
11
|
-
num_of_set =
|
12
|
-
num_of_set += 1 if
|
13
|
-
id_sets = num_of_set.times.map {|i|
|
21
|
+
num_of_set = users_array.size / 100
|
22
|
+
num_of_set += 1 if users_array.size % 100 > 0
|
23
|
+
id_sets = num_of_set.times.map {|i| users_array.slice(i*100, (i+1)*100)}
|
14
24
|
# send request
|
15
|
-
|
25
|
+
full_response = []
|
26
|
+
response = nil
|
16
27
|
id_sets.each do |set|
|
17
|
-
|
18
|
-
|
19
|
-
include_entities: include_entities
|
20
|
-
}
|
28
|
+
oauth = oauth_params(true)
|
29
|
+
query[users_array_type] = set.join(',')
|
21
30
|
method = set.size <= 10 ? :GET : :POST
|
22
|
-
|
31
|
+
response = send_request(method, PATH[:users_lookup], query, oauth)
|
32
|
+
if response[0]
|
33
|
+
full_response += response[1]
|
34
|
+
else
|
35
|
+
break
|
36
|
+
end
|
23
37
|
end
|
24
|
-
return
|
38
|
+
return results_with_error_explained(response, options, full_response)
|
39
|
+
end
|
40
|
+
|
41
|
+
def users_show(params, options={})
|
42
|
+
query = params.clone
|
43
|
+
oauth = oauth_params(true)
|
44
|
+
response = send_request(:GET, PATH[:users_show], query, oauth)
|
45
|
+
return results_with_error_explained(response, options)
|
46
|
+
end
|
47
|
+
|
48
|
+
def users_search(params, options={})
|
49
|
+
query = params.clone
|
50
|
+
oauth = oauth_params(true)
|
51
|
+
response = send_request(:GET, PATH[:users_search], query, oauth)
|
52
|
+
return results_with_error_explained(response, options)
|
53
|
+
end
|
54
|
+
|
55
|
+
def users_contributees(params, options={})
|
56
|
+
query = params.clone
|
57
|
+
oauth = oauth_params(true)
|
58
|
+
response = send_request(:GET, PATH[:users_contributees], query, oauth)
|
59
|
+
return results_with_error_explained(response, options)
|
60
|
+
end
|
61
|
+
|
62
|
+
def users_contributors(params, options={})
|
63
|
+
query = params.clone
|
64
|
+
oauth = oauth_params(true)
|
65
|
+
response = send_request(:GET, PATH[:users_contributors], query, oauth)
|
66
|
+
return results_with_error_explained(response, options)
|
67
|
+
end
|
68
|
+
|
69
|
+
##
|
70
|
+
#
|
71
|
+
def users_profile_banner(params={}, options={})
|
72
|
+
query = params.clone
|
73
|
+
oauth = oauth_params(true)
|
74
|
+
response = send_request(:GET, PATH[:users_profile_banner], query, oauth)
|
75
|
+
return results_with_error_explained(response, options)
|
25
76
|
end
|
26
77
|
|
27
78
|
end
|
data/lib/oauth_twitter/helper.rb
CHANGED
@@ -7,24 +7,44 @@ require "multi_json"
|
|
7
7
|
|
8
8
|
module OauthTwitter
|
9
9
|
module Helper
|
10
|
+
|
11
|
+
##
|
12
|
+
# Generate oauth params
|
10
13
|
def oauth_params(include_oauth_token=true, addional_oauth_params={})
|
11
14
|
oauth = {
|
12
|
-
oauth_consumer_key
|
13
|
-
oauth_nonce
|
14
|
-
oauth_signature_method
|
15
|
-
oauth_timestamp
|
16
|
-
oauth_version
|
15
|
+
:oauth_consumer_key => Config.consumer_key,
|
16
|
+
:oauth_nonce => SecureRandom.hex(21),
|
17
|
+
:oauth_signature_method => "HMAC-SHA1",
|
18
|
+
:oauth_timestamp => Time.now.to_i,
|
19
|
+
:oauth_version => "1.0"
|
17
20
|
}
|
18
|
-
oauth[:oauth_token] = self.oauth_token if include_oauth_token
|
21
|
+
oauth[:oauth_token] = self.oauth_token if include_oauth_token == true
|
19
22
|
return oauth.merge(addional_oauth_params)
|
20
23
|
end
|
21
24
|
|
25
|
+
##
|
26
|
+
# percent_encode disallowed char
|
22
27
|
RESERVED_CHARS = /[^a-zA-Z0-9\-\.\_\~]/
|
28
|
+
|
29
|
+
##
|
30
|
+
# percent_encode strigns
|
23
31
|
def self.percent_encode(raw)
|
24
32
|
return URI.escape(raw.to_s, RESERVED_CHARS)
|
25
33
|
end
|
26
34
|
|
35
|
+
##
|
36
|
+
# Twitter API root url
|
27
37
|
HOST = "https://api.twitter.com"
|
38
|
+
|
39
|
+
##
|
40
|
+
# Helper method to send request to Twitter API
|
41
|
+
# @param method [Symbol] HTTP method, support :GET or :POST
|
42
|
+
# @param path [String] request url path
|
43
|
+
# @param query [Hash] request parameters
|
44
|
+
# @param oauth [Hash] oauth request header
|
45
|
+
#
|
46
|
+
# @return [Array] 0: indicate successful or not, 1: response content,
|
47
|
+
# 2: error messages if any
|
28
48
|
def send_request(method, path, query, oauth)
|
29
49
|
# Make base_str and signing_key
|
30
50
|
base_str = method.to_s.upcase << "&"
|
@@ -36,7 +56,7 @@ module OauthTwitter
|
|
36
56
|
signing_key = String.new(Config.consumer_secret) << "&"
|
37
57
|
signing_key << self.oauth_token_secret if hash[:oauth_token]
|
38
58
|
signature = Helper.sign(base_str, signing_key)
|
39
|
-
signed_oauth = oauth.merge(oauth_signature
|
59
|
+
signed_oauth = oauth.merge(:oauth_signature => signature)
|
40
60
|
# Header
|
41
61
|
auth_header = Helper.auth_header(signed_oauth)
|
42
62
|
# HTTP request
|
@@ -52,29 +72,23 @@ module OauthTwitter
|
|
52
72
|
request = Net::HTTP::Get.new(uri.request_uri)
|
53
73
|
end
|
54
74
|
request["Authorization"] = auth_header
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
rescue SocketError
|
59
|
-
return false
|
60
|
-
end
|
75
|
+
##
|
76
|
+
# Might raise SocketError if no internet connection
|
77
|
+
response = https.request(request)
|
61
78
|
case response.code
|
62
79
|
when "200"
|
63
80
|
begin
|
64
|
-
return MultiJson.load(response.body)
|
81
|
+
return true, MultiJson.load(response.body)
|
65
82
|
rescue MultiJson::LoadError
|
66
|
-
return Rack::Utils.parse_nested_query(response.body)
|
83
|
+
return true, Rack::Utils.parse_nested_query(response.body)
|
67
84
|
end
|
68
|
-
when "401"
|
69
|
-
return false
|
70
|
-
when "408"
|
71
|
-
return false
|
72
85
|
else
|
73
|
-
|
74
|
-
raise "HTTP request failed."
|
86
|
+
return false, MultiJson.load(response.body), response.code
|
75
87
|
end
|
76
88
|
end
|
77
89
|
|
90
|
+
##
|
91
|
+
# Sign oauth params
|
78
92
|
def self.sign(base_str, signing_key)
|
79
93
|
hex_str = OpenSSL::HMAC.hexdigest(
|
80
94
|
OpenSSL::Digest::Digest.new('sha1'),
|
@@ -88,5 +102,18 @@ module OauthTwitter
|
|
88
102
|
params = signed_oauth.map { |key, val| "#{key}=\"#{val}\"" }
|
89
103
|
return "OAuth " << params.join(",")
|
90
104
|
end
|
105
|
+
|
106
|
+
def results_with_error_explained(response, options, full_response=nil)
|
107
|
+
if full_response && options[:explain_error] == true
|
108
|
+
return response[0] ? [response[0], full_response] : (response + [full_response])
|
109
|
+
elsif full_response
|
110
|
+
return full_response
|
111
|
+
elsif options[:explain_error] == true
|
112
|
+
return response
|
113
|
+
else
|
114
|
+
return response[0] ? response[1] : false
|
115
|
+
end
|
116
|
+
end
|
117
|
+
|
91
118
|
end
|
92
119
|
end
|
data/oauth_twitter.gemspec
CHANGED
@@ -8,9 +8,9 @@ Gem::Specification.new do |spec|
|
|
8
8
|
spec.version = OauthTwitter::VERSION
|
9
9
|
spec.authors = ["Daiwei Lu"]
|
10
10
|
spec.email = ["daiweilu123@gmail.com"]
|
11
|
-
spec.description = %q{
|
12
|
-
spec.summary = %q{
|
13
|
-
spec.homepage = ""
|
11
|
+
spec.description = %q{An OAuth library to interact with Twitter API v1.1, by simply calling methods on instances.}
|
12
|
+
spec.summary = %q{Load data from Twitter API}
|
13
|
+
spec.homepage = "https://github.com/daiweilu/oauth_twitter"
|
14
14
|
spec.license = "MIT"
|
15
15
|
|
16
16
|
spec.files = `git ls-files`.split($/)
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: oauth_twitter
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1
|
4
|
+
version: 0.2.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Daiwei Lu
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2013-05-
|
11
|
+
date: 2013-05-17 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -66,7 +66,8 @@ dependencies:
|
|
66
66
|
- - ~>
|
67
67
|
- !ruby/object:Gem::Version
|
68
68
|
version: '1.7'
|
69
|
-
description:
|
69
|
+
description: An OAuth library to interact with Twitter API v1.1, by simply calling
|
70
|
+
methods on instances.
|
70
71
|
email:
|
71
72
|
- daiweilu123@gmail.com
|
72
73
|
executables: []
|
@@ -87,7 +88,7 @@ files:
|
|
87
88
|
- lib/oauth_twitter/helper.rb
|
88
89
|
- lib/oauth_twitter/version.rb
|
89
90
|
- oauth_twitter.gemspec
|
90
|
-
homepage:
|
91
|
+
homepage: https://github.com/daiweilu/oauth_twitter
|
91
92
|
licenses:
|
92
93
|
- MIT
|
93
94
|
metadata: {}
|
@@ -110,5 +111,6 @@ rubyforge_project:
|
|
110
111
|
rubygems_version: 2.0.3
|
111
112
|
signing_key:
|
112
113
|
specification_version: 4
|
113
|
-
summary:
|
114
|
+
summary: Load data from Twitter API
|
114
115
|
test_files: []
|
116
|
+
has_rdoc:
|