rixi 0.1.2 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (4) hide show
  1. data/VERSION +1 -1
  2. data/lib/rixi.rb +62 -32
  3. data/rixi.gemspec +1 -1
  4. metadata +14 -14
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.2
1
+ 0.2.0
data/lib/rixi.rb CHANGED
@@ -1,7 +1,35 @@
1
1
  # -*- coding: utf-8 -*-
2
+ require 'cgi'
2
3
  require 'oauth2'
3
4
  require 'json'
4
5
 
6
+ module OAuth2
7
+ class Client
8
+ # Initializes an AccessToken by making a request to the token endpoint
9
+ #
10
+ # @param [Hash] params a Hash of params for the token endpoint
11
+ # @return [AccessToken] the initalized AccessToken
12
+ def get_token(params)
13
+ opts = { :raise_errors => true, :parse => params.delete(:parse)}
14
+ if options[:token_method] == :post
15
+ opts[:body] = params
16
+ opts[:headers] = { 'Content-Type' => 'application/x-www-form-urlencoded'}
17
+ else
18
+ opts[:params] = params
19
+ end
20
+ response = request(options[:token_method], token_url, opts)
21
+ raise Error.new(response) unless response.parsed.is_a?(Hash) && response.parsed['access_token']
22
+
23
+ ##
24
+ ## デフォルトではヘッダーでのAccessToken指定が出来ないため
25
+ ##
26
+ AccessToken.new(self, response.parsed.delete("access_token"),
27
+ :mode => :header,
28
+ :header_format => "OAuth %s")
29
+ end
30
+ end
31
+ end
32
+
5
33
  class Rixi
6
34
  class APIError < StandardError
7
35
  attr_reader :response
@@ -52,8 +80,7 @@ class Rixi
52
80
 
53
81
  def get_token(code)
54
82
  @token = @client.auth_code
55
- .get_token(code,
56
- {:redirect_uri => @redirect_uri})
83
+ .get_token(code,{:redirect_uri => @redirect_uri})
57
84
  end
58
85
 
59
86
  #
@@ -95,20 +122,21 @@ class Rixi
95
122
  delete_replies /2/voice/replies/destroy/%s/%s post
96
123
  create_favorite /2/voice/favorites/create/%s post
97
124
  delete_favorite /2/voice/favorites/destory/%s/%s post
98
- album /2/photo/albums/%s/@self/%o get
125
+ albums /2/photo/albums/%s/@self/%o get
99
126
  recent_album /2/photo/albums/%s/%s get
100
- mediaitmes /2/photo/mediaItems/%s/@self/%s/%o get
101
- recent_media /2/photo/mediaItems/%s/%o      get
127
+ photos_in_album /2/photo/mediaItems/%s/@self/%s/%o get
128
+ recent_photos /2/photo/mediaItems/%s/%o      get
102
129
  comments_album /2/photo/comments/albums/%s/@self/%s get
103
- comments_media /2/photo/comments/mediaItems/%s/@self/%s/%s get
104
- favorites_media /2/phoho/favorites/mediaItems/%s/@self/%s/%s get
130
+ comments_photo /2/photo/comments/mediaItems/%s/@self/%s/%s get
131
+ favorites_photo /2/phoho/favorites/mediaItems/%s/@self/%s/%s get
105
132
  create_album /2/photo/albums/%s/@self post
106
133
  delete_album /2/photo/albums/%s/@self/%s delete
107
134
  create_comment_album /2/photo/comments/albums/%s/@self/%s post
108
135
  delete_comment_album /2/photo/comments/albums/%s/@self/%s/%s delete
109
- create_comment_media /2/photo/comments/mediaItems/%s/@self/%s/%s/ delete
110
- create_favorite_media /2/photo/favorites/mediaItems/%s/@self/%s/%s/ post
111
- delete_favorite_media /2/photo/favorites/mediaItems/%s/@self/%s/%s/ delete
136
+ upload_photo /2/photo/mediaItems/%s/@self/%s post_image
137
+ create_comment_photo /2/photo/comments/mediaItems/%s/@self/%s/%s/ delete
138
+ create_favorite_photo /2/photo/favorites/mediaItems/%s/@self/%s/%s/ post
139
+ delete_favorite_photo /2/photo/favorites/mediaItems/%s/@self/%s/%s/ delete
112
140
  messages_inbox /2/messages/%s/@inbox/%o get
113
141
  messages_outbox /2/messages/%s/@outbox/%o get
114
142
  create_message /2/messages/%s/@self/@outbox post
@@ -128,18 +156,15 @@ class Rixi
128
156
  if /%s/ =~ path
129
157
  define_method method_name do |*args|
130
158
  params = args.last.kind_of?(Hash) ? args.pop : { }
131
- __send__ http_method, path % args, params
132
- end
133
- elsif /%o/ =~ path
134
- define_method method_name do |*args|
135
- params = args.last.kind_of?(Hash) ? args.pop : { }
136
- if params.key? :optional_path
137
- path.sub!("%o",params[:optional_path].to_s)
138
- else
139
- path.sub!("/%o","")
159
+ if /%o/ =~ path
160
+ if params.key? :optional_path
161
+ path.sub!("%o",params[:optional_path].to_s)
162
+ else
163
+ path.sub!("/%o","")
164
+ end
140
165
  end
141
166
  __send__ http_method, path % args, params
142
- end
167
+ end
143
168
  else
144
169
  define_method method_name do |params = { }|
145
170
  __send__ http_method, path, params
@@ -151,30 +176,36 @@ class Rixi
151
176
  # これらのメソッドを呼ぶ
152
177
  def get(path, params = { })
153
178
  extend_expire()
154
- parse_response(@token.get(path,
155
- {:mode => :query,
156
- :params => params.merge({:oauth_token => @token.token})}))
179
+ parse_response(@token.get(path, :params => params))
157
180
  end
158
181
 
159
182
  def post(path, params = { })
160
183
  extend_expire()
184
+ parse_response(@token.post(path,:params => params))
185
+ end
186
+
187
+ # img は "rb"で開いたFileのインスタンスで渡す
188
+ def post_image(path, params = { })
189
+ extend_expire()
190
+ path += "?title="+ CGI.escape(params[:title]) if params[:title]
161
191
  parse_response(@token.post(path,
162
- {:mode => :body,
163
- :params => params.merge({:oauth_token => @token.token})}))
192
+ {
193
+ :headers => {
194
+ :content_type => "image/jpeg",
195
+ :content_length => params[:image].size.to_s,
196
+ },
197
+ :body => params[:image].read
198
+ }))
164
199
  end
165
200
 
166
201
  def delete(path, params = { })
167
202
  extend_expire()
168
- parse_response(@token.delete(path,
169
- {:mode => :body,
170
- :params => params.merge({:oauth_token => @token.token})}))
203
+ parse_response(@token.delete(path, :params => params))
171
204
  end
172
205
 
173
206
  def put(path, params = { })
174
207
  extend_expire()
175
- parse_response(@token.put(path,
176
- {:mode => :body,
177
- :params => params.merge({:oauth_token => @token.token})}))
208
+ parse_response(@token.put(path, :params => params))
178
209
  end
179
210
 
180
211
  # OAuth2::AccessTokenの仕様上破壊的代入が出来ないため...
@@ -185,7 +216,6 @@ class Rixi
185
216
  end
186
217
 
187
218
  # mixiボイスの投稿を楽にするため
188
- # Update APIとかぶるか?!
189
219
  def voice_update(status)
190
220
  voice_statuses_update(:statsus => status)
191
221
  end
data/rixi.gemspec CHANGED
@@ -5,7 +5,7 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{rixi}
8
- s.version = "0.1.2"
8
+ s.version = "0.2.0"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = [%q{ainame }]
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rixi
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 0.2.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -13,7 +13,7 @@ date: 2011-08-18 00:00:00.000000000Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: oauth2
16
- requirement: &70149873289960 !ruby/object:Gem::Requirement
16
+ requirement: &70222871326180 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -21,10 +21,10 @@ dependencies:
21
21
  version: '0'
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *70149873289960
24
+ version_requirements: *70222871326180
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: json
27
- requirement: &70149873288680 !ruby/object:Gem::Requirement
27
+ requirement: &70222871325260 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ! '>='
@@ -32,10 +32,10 @@ dependencies:
32
32
  version: '0'
33
33
  type: :runtime
34
34
  prerelease: false
35
- version_requirements: *70149873288680
35
+ version_requirements: *70222871325260
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: rspec
38
- requirement: &70149873287700 !ruby/object:Gem::Requirement
38
+ requirement: &70222871324500 !ruby/object:Gem::Requirement
39
39
  none: false
40
40
  requirements:
41
41
  - - ! '>='
@@ -43,10 +43,10 @@ dependencies:
43
43
  version: 2.3.0
44
44
  type: :development
45
45
  prerelease: false
46
- version_requirements: *70149873287700
46
+ version_requirements: *70222871324500
47
47
  - !ruby/object:Gem::Dependency
48
48
  name: bundler
49
- requirement: &70149873286860 !ruby/object:Gem::Requirement
49
+ requirement: &70222871323880 !ruby/object:Gem::Requirement
50
50
  none: false
51
51
  requirements:
52
52
  - - ! '>='
@@ -54,10 +54,10 @@ dependencies:
54
54
  version: 1.0.0
55
55
  type: :development
56
56
  prerelease: false
57
- version_requirements: *70149873286860
57
+ version_requirements: *70222871323880
58
58
  - !ruby/object:Gem::Dependency
59
59
  name: jeweler
60
- requirement: &70149873286100 !ruby/object:Gem::Requirement
60
+ requirement: &70222871323340 !ruby/object:Gem::Requirement
61
61
  none: false
62
62
  requirements:
63
63
  - - ~>
@@ -65,10 +65,10 @@ dependencies:
65
65
  version: 1.6.4
66
66
  type: :development
67
67
  prerelease: false
68
- version_requirements: *70149873286100
68
+ version_requirements: *70222871323340
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: rcov
71
- requirement: &70149873285280 !ruby/object:Gem::Requirement
71
+ requirement: &70222871322840 !ruby/object:Gem::Requirement
72
72
  none: false
73
73
  requirements:
74
74
  - - ! '>='
@@ -76,7 +76,7 @@ dependencies:
76
76
  version: '0'
77
77
  type: :development
78
78
  prerelease: false
79
- version_requirements: *70149873285280
79
+ version_requirements: *70222871322840
80
80
  description: Rixi is a simply library for mixi graph api in Ruby.
81
81
  email: ainame954@facebook.com
82
82
  executables: []
@@ -113,7 +113,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
113
113
  version: '0'
114
114
  segments:
115
115
  - 0
116
- hash: 1741242612359883089
116
+ hash: 921506224466776057
117
117
  required_rubygems_version: !ruby/object:Gem::Requirement
118
118
  none: false
119
119
  requirements: