twitter_api 0.1.1 → 0.1.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 8a3db3bf69e15b1348027a86ef3ae6858278bede
4
- data.tar.gz: 232a03167de774f62b18e49b78479801e10666db
3
+ metadata.gz: 43a114e1feb00e8dd32a91acbd0903359e89d87d
4
+ data.tar.gz: f703b82e78be5ded9331bcc92cb6d269d4f4a5f5
5
5
  SHA512:
6
- metadata.gz: 17a2249100fca19646803041a5b4ce2590a22a00764b979ccb73ffd560dd70f3d6623c4dd02dcac13c3cd315d96848ac6b9ae3189f6d9a2b94039bd270bc1667
7
- data.tar.gz: a925350474fb0fae452f47fff15c4ce74a459e9e7852615cfa2e7d3866929669807f5b43860c583d4a1f91b2a1fa5e641737bd0b17cced116a1f99525daa28eb
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' => 'niwasawa',
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' => 'niwasawa',
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
- def authorization(method, url, params)
17
- SimpleOAuth::Header.new(method, url, params, @credentials).to_s
18
- end
19
-
20
- # @return StringIO or Tempfile
21
- def get(base_url, params)
22
- headers = {'Authorization' => authorization('GET', base_url, params)}
23
- url = base_url + '?' + URI.encode_www_form(params)
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
- # @return Net::HTTPResponse
29
- def post(base_url, params, data=nil)
30
- headers = {'Authorization' => authorization('POST', base_url, params)}
31
- url = base_url + '?' + URI.encode_www_form(params)
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 — Twitter Developers
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
- base_url = 'https://api.twitter.com/1.1/search/tweets.json'
44
- get(base_url, params)
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 — Twitter Developers
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
- base_url = 'https://api.twitter.com/1.1/statuses/mentions_timeline.json'
51
- get(base_url, params)
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 — Twitter Developers
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
- base_url = 'https://api.twitter.com/1.1/statuses/user_timeline.json'
58
- get(base_url, params)
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 — Twitter Developers
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
- base_url = 'https://api.twitter.com/1.1/statuses/update.json'
65
- post(base_url, params)
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
- # @return Net::HTTPHeader or Hash
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
- # @return String
133
+ # Returns HTTP body.
134
+ #
135
+ # @return [String]
89
136
  def body
90
137
  if @res.kind_of?(Net::HTTPResponse)
91
138
  @res.body
@@ -1,3 +1,3 @@
1
1
  module TwitterAPI
2
- VERSION = "0.1.1"
2
+ VERSION = "0.1.2"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: twitter_api
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Naoki Iwasawa