infomeme_client 0.2.8 → 0.2.10

Sign up to get free protection for your applications and to get access to all the features.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.2.8
1
+ 0.2.10
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{infomeme_client}
8
- s.version = "0.2.8"
8
+ s.version = "0.2.10"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Infomeme Ltd."]
12
- s.date = %q{2011-04-26}
12
+ s.date = %q{2011-06-09}
13
13
  s.description = %q{A RubyGem for implementing both Infomeme client and meme applications.
14
14
  More coming soon...}
15
15
  s.email = %q{infomeme@infomeme.com}
@@ -32,6 +32,7 @@ Gem::Specification.new do |s|
32
32
  "lib/infomeme_client/entity_hash/invoice.rb",
33
33
  "lib/infomeme_client/entity_hash/meme.rb",
34
34
  "lib/infomeme_client/entity_hash/meme_type.rb",
35
+ "lib/infomeme_client/entity_hash/review.rb",
35
36
  "lib/infomeme_client/entity_hash/transaction.rb",
36
37
  "lib/infomeme_client/entity_hash/user.rb",
37
38
  "lib/infomeme_client/errors.rb",
@@ -4,19 +4,19 @@ require "net/http/post/multipart"
4
4
  require "mime/types"
5
5
 
6
6
  class InfomemeClient
7
- require "infomeme_client/errors"
7
+ require "infomeme_client/errors"
8
8
 
9
- autoload :EntityHash, "infomeme_client/entity_hash"
10
- autoload :Response, "infomeme_client/response"
11
- autoload :Base, "infomeme_client/base"
12
- autoload :Communication, "infomeme_client/communication"
13
- autoload :Permissions, "infomeme_client/permissions"
14
- autoload :Functions, "infomeme_client/functions"
9
+ autoload :EntityHash, "infomeme_client/entity_hash"
10
+ autoload :Response, "infomeme_client/response"
11
+ autoload :Base, "infomeme_client/base"
12
+ autoload :Communication, "infomeme_client/communication"
13
+ autoload :Permissions, "infomeme_client/permissions"
14
+ autoload :Functions, "infomeme_client/functions"
15
15
 
16
- autoload :MemeApplication, "infomeme_client/meme_application"
16
+ autoload :MemeApplication, "infomeme_client/meme_application"
17
17
 
18
- include Base
19
- include Communication
20
- include Permissions
21
- include Functions
18
+ include Base
19
+ include Communication
20
+ include Permissions
21
+ include Functions
22
22
  end
@@ -1,77 +1,77 @@
1
1
  module InfomemeClient::Base
2
- def initialize(options = {})
3
- self.consumer = OAuth::Consumer.new(options[:api_key] || ::INFOMEME_API_KEY, options[:api_secret] || ::INFOMEME_API_SECRET, :site => options[:site] || ::INFOMEME_API_SITE)
4
- self.default_language = options[:language] || "en"
5
- case
2
+ def initialize(options = {})
3
+ self.consumer = OAuth::Consumer.new(options[:api_key] || ::INFOMEME_API_KEY, options[:api_secret] || ::INFOMEME_API_SECRET, :site => options[:site] || ::INFOMEME_API_SITE)
4
+ self.default_language = options[:language] || "en"
5
+ case
6
6
  when options.key?(:token) && options.key?(:secret) then authorize_with_token(options[:token], options[:secret])
7
7
  when options.key?(:login) && options.key?(:password) then authorize_with_credentials(options[:login], options[:password])
8
8
  else deauthorize
9
- end
10
- end
9
+ end
10
+ end
11
11
 
12
- def request_authorization
13
- response = handle_response :get, consumer.request_token_url
14
- response.request_token
15
- end
12
+ def request_authorization
13
+ response = handle_response :get, consumer.request_token_url
14
+ response.request_token
15
+ end
16
16
 
17
- def authorize_url(token, permissions = [])
18
- "https://infomeme.com/authorize?token=#{token}&permissions=#{permissions.join(',')}"
19
- end
17
+ def authorize_url(token, permissions = [])
18
+ "https://infomeme.com/authorize?token=#{token}&permissions=#{permissions.join(',')}"
19
+ end
20
20
 
21
- def authorize_with_verifier(token, secret, verifier)
22
- req_token = OAuth::RequestToken.new(consumer, token, secret)
23
- response = token_request(req_token, :get, finalize_get_url(consumer.access_token_url, {:oauth_verifier => verifier})) #do request with request_token
24
- return false if response.error?
25
- authorize_with_token(response.access_token.token, response.access_token.secret)
26
- end
21
+ def authorize_with_verifier(token, secret, verifier)
22
+ req_token = OAuth::RequestToken.new(consumer, token, secret)
23
+ response = token_request(req_token, :get, finalize_get_url(consumer.access_token_url, {:oauth_verifier => verifier})) #do request with request_token
24
+ return false if response.error?
25
+ authorize_with_token(response.access_token.token, response.access_token.secret)
26
+ end
27
27
 
28
- def authorize_with_token(token, secret)
29
- access_token = OAuth::AccessToken.new(consumer, token, secret)
30
- response = token_request(access_token, :get, "/oauth/verify_access")
31
- return false if response.error?
32
- self.verified_user = response.user_id
33
- self.token = access_token
34
- refresh_user_data
35
- self
36
- end
28
+ def authorize_with_token(token, secret)
29
+ access_token = OAuth::AccessToken.new(consumer, token, secret)
30
+ response = token_request(access_token, :get, "/oauth/verify_access")
31
+ return false if response.error?
32
+ self.verified_user = response.user_id
33
+ self.token = access_token
34
+ refresh_user_data
35
+ self
36
+ end
37
37
 
38
- def authorize_with_credentials(login, password, permissions = nil)
39
- req_token = request_authorization
40
- response = put(consumer.authorize_url, {:oauth_token => req_token.token, :login => login, :password => password, :permissions => permissions || all_permissions.collect {|perm| perm.id}})
41
- return false if response.error?
42
- authorize_with_verifier(req_token.token, req_token.secret, response.verifier)
43
- end
38
+ def authorize_with_credentials(login, password, permissions = nil)
39
+ req_token = request_authorization
40
+ response = put(consumer.authorize_url, {:oauth_token => req_token.token, :login => login, :password => password, :permissions => permissions || all_permissions.collect {|perm| perm.id}})
41
+ return false if response.error?
42
+ authorize_with_verifier(req_token.token, req_token.secret, response.verifier)
43
+ end
44
44
 
45
- def deauthorize
46
- self.verified_user = nil
47
- self.token = OAuth::AccessToken.new(consumer)
48
- refresh_user_data
49
- self
50
- end
45
+ def deauthorize
46
+ self.verified_user = nil
47
+ self.token = OAuth::AccessToken.new(consumer)
48
+ refresh_user_data
49
+ self
50
+ end
51
51
 
52
- def authorized?
53
- ! verified_user.nil?
54
- end
52
+ def authorized?
53
+ ! verified_user.nil?
54
+ end
55
55
 
56
- def credentials(just = nil)
57
- creds = {
58
- :login => verified_user,
59
- :token => token.token,
60
- :secret => token.secret,
61
- }
62
- creds.key?(just) ? creds[just] : creds
63
- end
56
+ def credentials(just = nil)
57
+ creds = {
58
+ :login => verified_user,
59
+ :token => token.token,
60
+ :secret => token.secret,
61
+ }
62
+ creds.key?(just) ? creds[just] : creds
63
+ end
64
64
 
65
- def inspect
66
- @all_permissions ||= all_permissions
67
- "#<#{self.class.name}: #{authorized? ? credentials.merge({:permissions => (@all_permissions || []).select {|perm| has_permission?(perm.id)}.collect {|perm| perm.name}}).inspect : 'not authorized'}>"
68
- end
65
+ def inspect
66
+ @all_permissions ||= all_permissions
67
+ "#<#{self.class.name}: #{authorized? ? credentials.merge({:permissions => (@all_permissions || []).select {|perm| has_permission?(perm.id)}.collect {|perm| perm.name}}).inspect : 'not authorized'}>"
68
+ end
69
69
 
70
- private
71
- attr_accessor :consumer, :token, :verified_user
70
+ private
71
+ attr_accessor :consumer, :token, :verified_user
72
72
 
73
- def refresh_user_data
74
- refresh_settings
75
- refresh_permissions
76
- end
73
+ def refresh_user_data
74
+ refresh_settings
75
+ refresh_permissions
76
+ end
77
77
  end
@@ -1,66 +1,66 @@
1
1
  class InfomemeClient::EntityHash
2
- autoload :Comment, "infomeme_client/entity_hash/comment"
3
- autoload :Invoice, "infomeme_client/entity_hash/invoice"
4
- autoload :Meme, "infomeme_client/entity_hash/meme"
5
- autoload :MemeType, "infomeme_client/entity_hash/meme_type"
6
- autoload :Transaction, "infomeme_client/entity_hash/transaction"
7
- autoload :User, "infomeme_client/entity_hash/user"
2
+ autoload :Comment, "infomeme_client/entity_hash/comment"
3
+ autoload :Invoice, "infomeme_client/entity_hash/invoice"
4
+ autoload :Meme, "infomeme_client/entity_hash/meme"
5
+ autoload :MemeType, "infomeme_client/entity_hash/meme_type"
6
+ autoload :Transaction, "infomeme_client/entity_hash/transaction"
7
+ autoload :User, "infomeme_client/entity_hash/user"
8
8
 
9
- def initialize(hsh, no_freeze = false)
10
- @hsh = hsh.inject({}) {|memo, keyvalue| #ripped from ActiveSupport, http://api.rubyonrails.org/classes/ActiveSupport/CoreExtensions/Hash/Keys.html#M000904
9
+ def initialize(hsh, no_freeze = false)
10
+ @hsh = hsh.inject({}) {|memo, keyvalue| #ripped from ActiveSupport, http://api.rubyonrails.org/classes/ActiveSupport/CoreExtensions/Hash/Keys.html#M000904
11
11
  key, value = keyvalue
12
12
  memo[(key.to_sym rescue key) || key] = map_values(value)
13
13
  memo
14
- }
15
- freeze unless no_freeze
16
- end
14
+ }
15
+ freeze unless no_freeze
16
+ end
17
17
 
18
- def method_missing(sym)
19
- @hsh.key?(sym) ? @hsh[sym] : super
20
- end
18
+ def method_missing(sym)
19
+ @hsh.key?(sym) ? @hsh[sym] : super
20
+ end
21
21
 
22
- def respond_to?(sym, include_private = false)
23
- @hsh.key?(sym) ? true : super
24
- end
22
+ def respond_to?(sym, include_private = false)
23
+ @hsh.key?(sym) ? true : super
24
+ end
25
25
 
26
- def to_hash
27
- @hsh.inject({}) do |memo, (key, value)|
28
- memo[key] = extract_values(value)
29
- memo
30
- end
26
+ def to_hash
27
+ @hsh.inject({}) do |memo, (key, value)|
28
+ memo[key] = extract_values(value)
29
+ memo
31
30
  end
31
+ end
32
32
 
33
- def freeze
34
- @hsh.each do |key, val|
35
- deep_freeze(val)
36
- end
37
- @hsh.freeze
38
- super
33
+ def freeze
34
+ @hsh.each do |key, val|
35
+ deep_freeze(val)
39
36
  end
37
+ @hsh.freeze
38
+ super
39
+ end
40
40
 
41
- def id
42
- @hsh.key?(:id) ? @hsh[:id] : super
43
- end
41
+ def id
42
+ @hsh.key?(:id) ? @hsh[:id] : super
43
+ end
44
44
 
45
- private
46
- def map_values(val)
47
- case
48
- when val.is_a?(Hash) then InfomemeClient::EntityHash.new(val)
49
- when val.is_a?(Array) then val.collect {|obj| map_values(obj)}
50
- else val
51
- end
52
- end
45
+ private
46
+ def map_values(val)
47
+ case
48
+ when val.is_a?(Hash) then InfomemeClient::EntityHash.new(val)
49
+ when val.is_a?(Array) then val.collect {|obj| map_values(obj)}
50
+ else val
51
+ end
52
+ end
53
53
 
54
54
  def extract_values(val)
55
- case
56
- when val.is_a?(InfomemeClient::EntityHash) then val.to_hash
57
- when val.is_a?(Array) then val.collect {|obj| extract_values(obj)}
58
- else val
59
- end
55
+ case
56
+ when val.is_a?(InfomemeClient::EntityHash) then val.to_hash
57
+ when val.is_a?(Array) then val.collect {|obj| extract_values(obj)}
58
+ else val
59
+ end
60
60
  end
61
61
 
62
62
  def deep_freeze(val)
63
- val.each {|obj| deep_freeze(obj)} if val.is_a?(Array)
64
- val.freeze
63
+ val.each {|obj| deep_freeze(obj)} if val.is_a?(Array)
64
+ val.freeze
65
65
  end
66
66
  end
@@ -1,45 +1,49 @@
1
1
  class InfomemeClient::EntityHash::Meme < InfomemeClient::EntityHash
2
- def initialize(meme, client)
3
- super(meme, true)
4
- @client = client
5
- freeze
6
- end
2
+ def initialize(meme, client)
3
+ super(meme, true)
4
+ @client = client
5
+ freeze
6
+ end
7
7
 
8
- #todo: have_access?, published_by_me?, confirmed?, inactive?, incomplete?, has_upload?, etc.
8
+ #todo: have_access?, published_by_me?, confirmed?, inactive?, incomplete?, has_upload?, etc.
9
9
 
10
- def update(options = {})
11
- @client.update_meme(id, options)
12
- end
10
+ def update(options = {})
11
+ @client.update_meme(id, options)
12
+ end
13
13
 
14
- def delete
15
- @client.delete_meme(id)
16
- end
14
+ def delete
15
+ @client.delete_meme(id)
16
+ end
17
17
 
18
- def confirm
19
- @client.confirm_meme(id)
20
- end
18
+ def confirm
19
+ @client.confirm_meme(id)
20
+ end
21
21
 
22
- def activate
23
- @client.activate_meme(id)
24
- end
22
+ def activate
23
+ @client.activate_meme(id)
24
+ end
25
25
 
26
- def deactivate
27
- @client.deactivate_meme(id)
28
- end
26
+ def deactivate
27
+ @client.deactivate_meme(id)
28
+ end
29
29
 
30
- def upload_url(raw = false)
31
- @client.upload_for_meme(id, raw)
32
- end
30
+ def upload_url(raw = false)
31
+ @client.upload_for_meme(id, raw)
32
+ end
33
33
 
34
- def upload(file)
35
- @client.upload(id, file)
36
- end
34
+ def upload(file)
35
+ @client.upload(id, file)
36
+ end
37
37
 
38
- def rate(rating)
39
- @client.rate(id, rating)
40
- end
38
+ def review(reveiw)
39
+ @client.review id, review
40
+ end
41
41
 
42
- def comment(comment)
43
- @client.comment(id, comment)
44
- end
42
+ def rate(rating)
43
+ @client.rate(id, rating)
44
+ end
45
+
46
+ def comment(comment)
47
+ @client.comment(id, comment)
48
+ end
45
49
  end
@@ -0,0 +1,2 @@
1
+ class InfomemeClient::EntityHash::Review < InfomemeClient::EntityHash
2
+ end
@@ -1,23 +1,23 @@
1
1
  module InfomemeClient::Functions::Meme
2
- def browse(options = {})
3
- get_memes "/memes", options
4
- end
2
+ def browse(options = {})
3
+ get_memes "/memes", options
4
+ end
5
5
 
6
- def search(search_token, options = {})
7
- get_memes "/memes/search", options.merge({:search_token => search_token})
8
- end
6
+ def search(search_token, options = {})
7
+ get_memes "/memes/search", options.merge({:search_token => search_token})
8
+ end
9
9
 
10
- def meme_types
11
- extract_from_response :meme_types, :get, "/memes/types"
12
- end
10
+ def meme_types
11
+ extract_from_response :meme_types, :get, "/memes/types"
12
+ end
13
13
 
14
- def meme(meme_id)
15
- handle_response :get, "/memes/#{meme_id}" do |resp|
16
- resp.extract(:meme, self) unless resp.error?
17
- end
14
+ def meme(meme_id)
15
+ handle_response :get, "/memes/#{meme_id}" do |resp|
16
+ resp.extract(:meme, self) unless resp.error?
18
17
  end
18
+ end
19
19
 
20
- def meme_comments(meme_id, options = {})
21
- extract_or_response :comments, :get, "/memes/#{meme_id}/comments", options
22
- end
20
+ def meme_comments(meme_id, options = {})
21
+ extract_or_response :comments, :get, "/memes/#{meme_id}/comments", options
22
+ end
23
23
  end
@@ -1,79 +1,78 @@
1
1
  module InfomemeClient::Functions::User
2
- attr_accessor :default_language
3
-
4
- def register(email, username, password, firstname, lastname, optional_fields = {})
5
- optional_fields.store(:language_code, optional_fields.key?(:language) ? optional_fields.delete(:language) : default_language) #language is mandatory
6
- handle_response :post, "/users/register", optional_fields.merge({:email => email, :username => username, :password => password, :firstname => firstname, :lastname => lastname}) do
7
- authorize_with_credentials username, password and return true
8
- end
2
+ attr_accessor :default_language
3
+ def register(email, username, password, firstname, lastname, optional_fields = {})
4
+ optional_fields.store(:language_code, optional_fields.key?(:language) ? optional_fields.delete(:language) : default_language) #language is mandatory
5
+ handle_response :post, "/users/register", optional_fields.merge({:email => email, :username => username, :password => password, :firstname => firstname, :lastname => lastname}) do
6
+ authorize_with_credentials username, password and return true
9
7
  end
8
+ end
10
9
 
11
- def user(user_id = nil)
12
- return false if ! authorized? && user_id.nil?
13
- extract_from_response :user, :get, "/users/#{user_id || verified_user}"
14
- end
10
+ def user(user_id = nil)
11
+ return false if ! authorized? && user_id.nil?
12
+ extract_from_response :user, :get, "/users/#{user_id || verified_user}"
13
+ end
15
14
 
16
- def update_settings(attribs = {})
17
- return false unless authorized?
18
- handle_response :put, "/users/#{verified_user}", attribs do
19
- refresh_settings and return true
20
- end
15
+ def update_settings(attribs = {})
16
+ return false unless authorized?
17
+ handle_response :put, "/users/#{verified_user}", attribs do
18
+ refresh_settings and return true
21
19
  end
20
+ end
22
21
 
23
- def confirm(confirm_code)
24
- return false unless authorized?
25
- handle_response :put, "/users/#{verified_user}/confirm", {:confirm_code => confirm_code} do
26
- refresh_settings and return true
27
- end
22
+ def confirm(confirm_code)
23
+ return false unless authorized?
24
+ handle_response :put, "/users/#{verified_user}/confirm", {:confirm_code => confirm_code} do
25
+ refresh_settings and return true
28
26
  end
27
+ end
29
28
 
30
- def confirmed?
31
- authorized? && settings && settings.confirmed
32
- end
29
+ def confirmed?
30
+ authorized? && settings && settings.confirmed
31
+ end
33
32
 
34
- def reset_password(user_id = nil)
35
- return false if ! authorized? && user_id.nil?
36
- handle_response :get, "/users/#{user_id || verified_user}/reset_password"
37
- end
33
+ def reset_password(user_id = nil)
34
+ return false if ! authorized? && user_id.nil?
35
+ handle_response :get, "/users/#{user_id || verified_user}/reset_password"
36
+ end
38
37
 
39
- def new_password(new_password, user_id = nil, confirm_code = "")
40
- return false if ! authorized? && user_id.nil?
41
- handle_response :put, "/users/#{user_id || verified_user}/new_password", {:new_password => new_password}.merge(user_id.nil? ? {} : {:confirm_code => confirm_code})
42
- end
38
+ def new_password(new_password, user_id = nil, confirm_code = "")
39
+ return false if ! authorized? && user_id.nil?
40
+ handle_response :put, "/users/#{user_id || verified_user}/new_password", {:new_password => new_password}.merge(user_id.nil? ? {} : {:confirm_code => confirm_code})
41
+ end
43
42
 
44
- def accept_tos
45
- return false unless authorized?
46
- handle_response :put, "/users/#{verified_user}/accept_tos" do
47
- refresh_settings and return true
48
- end
43
+ def accept_tos
44
+ return false unless authorized?
45
+ handle_response :put, "/users/#{verified_user}/accept_tos" do
46
+ refresh_settings and return true
49
47
  end
48
+ end
50
49
 
51
- def countries
52
- handle_response :get, "/users/countries" do |resp|
53
- resp.countries unless resp.error?
54
- end
50
+ def countries
51
+ handle_response :get, "/users/countries" do |resp|
52
+ resp.countries unless resp.error?
55
53
  end
54
+ end
56
55
 
57
- def currencies
58
- handle_response :get, "/users/currencies" do |resp|
59
- resp.currencies unless resp.error?
60
- end
56
+ def currencies
57
+ handle_response :get, "/users/currencies" do |resp|
58
+ resp.currencies unless resp.error?
61
59
  end
60
+ end
62
61
 
63
- def languages
64
- handle_response :get, "/users/languages" do |resp|
65
- resp.languages unless resp.error?
66
- end
62
+ def languages
63
+ handle_response :get, "/users/languages" do |resp|
64
+ resp.languages unless resp.error?
67
65
  end
66
+ end
68
67
 
69
- private
70
- attr_accessor :settings
68
+ private
69
+ attr_accessor :settings
71
70
 
72
- def refresh_settings
73
- self.settings = nil
74
- return false unless authorized?
75
- response = get("/users/#{verified_user}")
76
- return false if response.error?
77
- self.settings = response.user
78
- end
71
+ def refresh_settings
72
+ self.settings = nil
73
+ return false unless authorized?
74
+ response = get("/users/#{verified_user}")
75
+ return false if response.error?
76
+ self.settings = response.user
77
+ end
79
78
  end
@@ -83,6 +83,16 @@ module InfomemeClient::Functions::UserMeme
83
83
  File.basename(file.path) if upload_params && http_multipart("https://#{upload_params.bucket}.s3.amazonaws.com/", upload_params.to_hash.reject {|k,v| k == :bucket}.merge(:success_action_status => 200).to_a.push([:file, uploadio(file)])) #ensure file comes last (amazon requires the order)
84
84
  end
85
85
 
86
+ def review(meme_id, review)
87
+ return false unless authorized?
88
+ handle_response :post, "/users/#{verified_user}/memes/#{meme_id}/reviews", {:review => review}
89
+ end
90
+
91
+ def review(meme_id, rating, comment)
92
+ return false unless authorized?
93
+ handle_response :post, "/users/#{verified_user}/memes/#{meme_id}/reviews", {:rating => rating, :comment => comment}
94
+ end
95
+
86
96
  def rate(meme_id, rating)
87
97
  return false unless authorized?
88
98
  handle_response :post, "/users/#{verified_user}/memes/#{meme_id}/rates", {:rating => rating}
@@ -1,31 +1,31 @@
1
1
  module InfomemeClient::Functions::UserOrder
2
- def order(meme_id, source, options = {})
3
- return false unless authorized?
4
- handle_response :post, "/users/#{verified_user}/memes/#{meme_id}/order", options.merge(:source => source)
5
- end
2
+ def order(meme_id, source, options = {})
3
+ return false unless authorized?
4
+ handle_response :post, "/users/#{verified_user}/memes/#{meme_id}/order", options.merge(:source => source)
5
+ end
6
6
 
7
- def order_with_balance(meme_id, options = {})
8
- order(meme_id, 1, options)
9
- refresh_settings
10
- true
11
- end
7
+ def order_with_balance(meme_id, options = {})
8
+ order(meme_id, 1, options)
9
+ refresh_settings
10
+ true
11
+ end
12
12
 
13
- def order_with_paypal(meme_id, options = {})
14
- order(meme_id, 3, options).paypal_url
15
- end
13
+ def order_with_paypal(meme_id, options = {})
14
+ order(meme_id, 3, options).paypal_url
15
+ end
16
16
 
17
- def transactions(options = {})
18
- return false unless authorized?
19
- extract_or_response :transactions, :get, "/users/#{verified_user}/transactions", options
20
- end
17
+ def transactions(options = {})
18
+ return false unless authorized?
19
+ extract_or_response :transactions, :get, "/users/#{verified_user}/transactions", options
20
+ end
21
21
 
22
- def invoices(options = {})
23
- return false unless authorized?
24
- extract_or_response :invoices, :get, "/users/#{verified_user}/invoices", options
25
- end
22
+ def invoices(options = {})
23
+ return false unless authorized?
24
+ extract_or_response :invoices, :get, "/users/#{verified_user}/invoices", options
25
+ end
26
26
 
27
- def invoice(invoice_id)
28
- return false unless authorized?
29
- extract_from_response :invoice, :get, "/users/#{verified_user}/invoices/#{invoice_id}"
30
- end
27
+ def invoice(invoice_id)
28
+ return false unless authorized?
29
+ extract_from_response :invoice, :get, "/users/#{verified_user}/invoices/#{invoice_id}"
30
+ end
31
31
  end
@@ -1,18 +1,18 @@
1
1
  class InfomemeClient::MemeApplication
2
- def initialize(options = {})
3
- self.consumer = OAuth::Consumer.new(options[:api_key] || ::INFOMEME_API_KEY, options[:api_secret] || ::INFOMEME_API_SECRET, :site => options[:site] || ::INFOMEME_API_SITE)
4
- self.token = OAuth::AccessToken.new(consumer)
5
- end
2
+ def initialize(options = {})
3
+ self.consumer = OAuth::Consumer.new(options[:api_key] || ::INFOMEME_API_KEY, options[:api_secret] || ::INFOMEME_API_SECRET, :site => options[:site] || ::INFOMEME_API_SITE)
4
+ self.token = OAuth::AccessToken.new(consumer)
5
+ end
6
6
 
7
- def verify_access(access_type, meme_id, oauth_token, oauth_nonce, oauth_timestamp, oauth_signature)
8
- handle_response :post, "/meme_app/verify_access", {:access_type => access_type, :meme_id => meme_id, :verify_token => oauth_token, :verify_nonce => oauth_nonce, :verify_timestamp => oauth_timestamp, :verify_signature => oauth_signature}
9
- end
7
+ def verify_access(access_type, meme_id, oauth_token, oauth_nonce, oauth_timestamp, oauth_signature)
8
+ handle_response :post, "/meme_app/verify_access", {:access_type => access_type, :meme_id => meme_id, :verify_token => oauth_token, :verify_nonce => oauth_nonce, :verify_timestamp => oauth_timestamp, :verify_signature => oauth_signature}
9
+ end
10
10
 
11
- def update_meme(meme_id, description, has_upload = true)
12
- handle_response :put, "/meme_app/memes/#{meme_id}", {:description => description, :has_upload => has_upload}
13
- end
11
+ def update_meme(meme_id, description, has_upload = true)
12
+ handle_response :put, "/meme_app/memes/#{meme_id}", {:description => description, :has_upload => has_upload}
13
+ end
14
14
 
15
- private
16
- attr_accessor :consumer, :token
17
- include InfomemeClient::Communication
15
+ private
16
+ attr_accessor :consumer, :token
17
+ include InfomemeClient::Communication
18
18
  end
@@ -1,22 +1,22 @@
1
1
  module InfomemeClient::Permissions
2
- def all_permissions
3
- handle_response :get, "/oauth/permissions" do |resp|
4
- resp.permissions unless resp.error?
5
- end
2
+ def all_permissions
3
+ handle_response :get, "/oauth/permissions" do |resp|
4
+ resp.permissions unless resp.error?
6
5
  end
6
+ end
7
7
 
8
- def has_permission?(perm)
9
- authorized? && permissions && permissions.include?(perm)
10
- end
8
+ def has_permission?(perm)
9
+ authorized? && permissions && permissions.include?(perm)
10
+ end
11
11
 
12
- private
13
- attr_accessor :permissions
12
+ private
13
+ attr_accessor :permissions
14
14
 
15
- def refresh_permissions
16
- self.permissions = nil
17
- return false unless authorized?
18
- response = get "/users/#{verified_user}/permissions"
19
- return false if response.error?
20
- self.permissions = response.permissions
21
- end
15
+ def refresh_permissions
16
+ self.permissions = nil
17
+ return false unless authorized?
18
+ response = get "/users/#{verified_user}/permissions"
19
+ return false if response.error?
20
+ self.permissions = response.permissions
21
+ end
22
22
  end
@@ -1,52 +1,52 @@
1
1
  class InfomemeClient::Response < InfomemeClient::EntityHash
2
- STATUS_FAILED = -1
3
- STATUS_OK = 0
4
- STATUS_ERROR = 1
2
+ STATUS_FAILED = -1
3
+ STATUS_OK = 0
4
+ STATUS_ERROR = 1
5
5
 
6
- ERRORS = {
7
- "request_failed" => InfomemeClient::Error::RequestFailed,
8
- "error" => InfomemeClient::Error,
9
- "internal_error" => InfomemeClient::Error::InternalError,
10
- "no_access" => InfomemeClient::Error::NoAccess,
11
- "not_found" => InfomemeClient::Error::NotFound,
12
- }.freeze
6
+ ERRORS = {
7
+ "request_failed" => InfomemeClient::Error::RequestFailed,
8
+ "error" => InfomemeClient::Error,
9
+ "internal_error" => InfomemeClient::Error::InternalError,
10
+ "no_access" => InfomemeClient::Error::NoAccess,
11
+ "not_found" => InfomemeClient::Error::NotFound,
12
+ }.freeze
13
13
 
14
- def initialize(response)
15
- super(response.is_a?(Exception) ? {:status => STATUS_FAILED, :message => "Request failed.", :error_code => "request_failed", :errors => {:base => {response.class.name.to_sym => response.message}}} : response, true)
16
- ERRORS.each do |key, val|
17
- instance_eval "def #{val.name.split('::').last.sub(/\b\w/) { $&.downcase }}Error?; error_code == #{key}; end"
18
- end
19
- freeze
14
+ def initialize(response)
15
+ super(response.is_a?(Exception) ? {:status => STATUS_FAILED, :message => "Request failed.", :error_code => "request_failed", :errors => {:base => {response.class.name.to_sym => response.message}}} : response, true)
16
+ ERRORS.each do |key, val|
17
+ instance_eval "def #{val.name.split('::').last.sub(/\b\w/) { $&.downcase }}Error?; error_code == #{key}; end"
20
18
  end
19
+ freeze
20
+ end
21
21
 
22
- def failed?
23
- status == STATUS_FAILED
24
- end
22
+ def failed?
23
+ status == STATUS_FAILED
24
+ end
25
25
 
26
- def error?
27
- status != STATUS_OK
28
- end
26
+ def error?
27
+ status != STATUS_OK
28
+ end
29
29
 
30
- def raise_error(options = {})
31
- return false unless error?
32
- return false if options.key?(:only) && ! options[:only].include?(error_code)
33
- return false if options.key?(:except) && options[:except].include?(error_code)
34
- err = ERRORS.key?(error_code) ? ERRORS[error_code] : InfomemeClient::Error
35
- raise err, [(respond_to?(:errors) ? errors.to_hash : nil), message]
36
- end
30
+ def raise_error(options = {})
31
+ return false unless error?
32
+ return false if options.key?(:only) && ! options[:only].include?(error_code)
33
+ return false if options.key?(:except) && options[:except].include?(error_code)
34
+ err = ERRORS.key?(error_code) ? ERRORS[error_code] : InfomemeClient::Error
35
+ raise err, [(respond_to?(:errors) ? errors.to_hash : nil), message]
36
+ end
37
37
 
38
- def extract(key, *extra_args)
39
- return nil unless @hsh.key?(key)
40
- klass = case key
41
- when :comments then InfomemeClient::EntityHash::Comment
42
- when :meme, :memes then InfomemeClient::EntityHash::Meme
43
- when :meme_types then InfomemeClient::EntityHash::MemeType
44
- when :user then InfomemeClient::EntityHash::User
45
- when :transactions then InfomemeClient::EntityHash::Transaction
46
- when :invoice, :invoices then InfomemeClient::EntityHash::Invoice
47
- else InfomemeClient::EntityHash
48
- end
49
- stored = to_hash[key]
50
- stored.is_a?(Array) ? stored.collect {|val| klass.new *[val, extra_args]} : klass.new(*[stored, extra_args])
38
+ def extract(key, *extra_args)
39
+ return nil unless @hsh.key?(key)
40
+ klass = case key
41
+ when :comments then InfomemeClient::EntityHash::Comment
42
+ when :meme, :memes then InfomemeClient::EntityHash::Meme
43
+ when :meme_types then InfomemeClient::EntityHash::MemeType
44
+ when :user then InfomemeClient::EntityHash::User
45
+ when :transactions then InfomemeClient::EntityHash::Transaction
46
+ when :invoice, :invoices then InfomemeClient::EntityHash::Invoice
47
+ else InfomemeClient::EntityHash
51
48
  end
49
+ stored = to_hash[key]
50
+ stored.is_a?(Array) ? stored.collect {|val| klass.new *[val, extra_args]} : klass.new(*[stored, extra_args])
51
+ end
52
52
  end
@@ -1,15 +1,15 @@
1
1
  require "helper"
2
2
 
3
3
  class TestEntityHash < Test::Unit::TestCase
4
- def test_entity_hash_attributes_available
5
- eh = InfomemeClient::EntityHash.new({:foo => "bar"})
6
- assert_respond_to eh, :foo
7
- assert_equal "bar", eh.foo
8
- end
4
+ def test_entity_hash_attributes_available
5
+ eh = InfomemeClient::EntityHash.new({:foo => "bar"})
6
+ assert_respond_to eh, :foo
7
+ assert_equal "bar", eh.foo
8
+ end
9
9
 
10
- def test_entity_hash_retrieve_hash
11
- hash = {:foo => "bar", :bar => [{:foo => "bar"}]}
12
- eh = InfomemeClient::EntityHash.new(hash)
13
- assert_equal hash, eh.to_hash
14
- end
10
+ def test_entity_hash_retrieve_hash
11
+ hash = {:foo => "bar", :bar => [{:foo => "bar"}]}
12
+ eh = InfomemeClient::EntityHash.new(hash)
13
+ assert_equal hash, eh.to_hash
14
+ end
15
15
  end
@@ -1,46 +1,46 @@
1
1
  require "helper"
2
2
 
3
3
  class TestMemeFunctions < Test::Unit::TestCase
4
- def test_browse
5
- fake_request(:get, "/memes?page=1&pageSize=25&sort=date-asc", :body => fixture("memes/memes"), :content_type => "application/json")
6
- check_paged :memes, @im_client.browse(:page => 1, :pageSize => 25, :sort => "date-asc", :no_extract => true)
7
- check_list :memes, @im_client.browse(:page => 1, :pageSize => 25, :sort => "date-asc")
8
- end
4
+ def test_browse
5
+ fake_request(:get, "/memes?page=1&pageSize=25&sort=date-asc", :body => fixture("memes/memes"), :content_type => "application/json")
6
+ check_paged :memes, @im_client.browse(:page => 1, :pageSize => 25, :sort => "date-asc", :no_extract => true)
7
+ check_list :memes, @im_client.browse(:page => 1, :pageSize => 25, :sort => "date-asc")
8
+ end
9
9
 
10
- def test_search
11
- fake_request(:get, "/memes/search?search_token=a&page=1&pageSize=25&sort=date-asc", :body => fixture("memes/memes"), :content_type => "application/json")
12
- check_paged :memes, @im_client.search("a", :page => 1, :pageSize => 25, :sort => "date-asc", :no_extract => true)
13
- check_list :memes, @im_client.search("a", :page => 1, :pageSize => 25, :sort => "date-asc")
14
- end
10
+ def test_search
11
+ fake_request(:get, "/memes/search?search_token=a&page=1&pageSize=25&sort=date-asc", :body => fixture("memes/memes"), :content_type => "application/json")
12
+ check_paged :memes, @im_client.search("a", :page => 1, :pageSize => 25, :sort => "date-asc", :no_extract => true)
13
+ check_list :memes, @im_client.search("a", :page => 1, :pageSize => 25, :sort => "date-asc")
14
+ end
15
15
 
16
- def test_meme_types
17
- fake_request(:get, "/memes/types", :body => fixture("memes/types"), :content_type => "application/json")
18
- types = @im_client.meme_types
19
- check_list :meme_types, types
20
- assert types.size > 0
21
- assert_respond_to types[0], :id
22
- assert_respond_to types[0], :name
23
- assert_respond_to types[0], :url
24
- assert_respond_to types[0], :summary
25
- assert_respond_to types[0], :description
26
- assert_equal 1, types[0].id
27
- assert_equal "TEST", types[0].name
28
- assert_equal "http://test.url", types[0].url
29
- assert_equal "test summary", types[0].summary
30
- assert_equal "test description", types[0].description
31
- end
16
+ def test_meme_types
17
+ fake_request(:get, "/memes/types", :body => fixture("memes/types"), :content_type => "application/json")
18
+ types = @im_client.meme_types
19
+ check_list :meme_types, types
20
+ assert types.size > 0
21
+ assert_respond_to types[0], :id
22
+ assert_respond_to types[0], :name
23
+ assert_respond_to types[0], :url
24
+ assert_respond_to types[0], :summary
25
+ assert_respond_to types[0], :description
26
+ assert_equal 1, types[0].id
27
+ assert_equal "TEST", types[0].name
28
+ assert_equal "http://test.url", types[0].url
29
+ assert_equal "test summary", types[0].summary
30
+ assert_equal "test description", types[0].description
31
+ end
32
32
 
33
- def test_meme
34
- fake_request(:get, "/memes/1", :body => fixture("memes/meme"), :content_type => "application/json")
35
- meme = @im_client.meme(1)
36
- check_eh :meme, meme
37
- assert_respond_to meme, :name
38
- assert_equal "test meme 1", meme.name
39
- end
33
+ def test_meme
34
+ fake_request(:get, "/memes/1", :body => fixture("memes/meme"), :content_type => "application/json")
35
+ meme = @im_client.meme(1)
36
+ check_eh :meme, meme
37
+ assert_respond_to meme, :name
38
+ assert_equal "test meme 1", meme.name
39
+ end
40
40
 
41
- def test_meme_comments
42
- fake_request(:get, "/memes/1/comments?page=1&pageSize=25", :body => fixture("memes/comments"), :content_type => "application/json")
43
- check_paged :comments, @im_client.meme_comments(1, :page => 1, :pageSize => 25, :no_extract => true)
44
- check_list :comments, @im_client.meme_comments(1, :page => 1, :pageSize => 25)
45
- end
41
+ def test_meme_comments
42
+ fake_request(:get, "/memes/1/comments?page=1&pageSize=25", :body => fixture("memes/comments"), :content_type => "application/json")
43
+ check_paged :comments, @im_client.meme_comments(1, :page => 1, :pageSize => 25, :no_extract => true)
44
+ check_list :comments, @im_client.meme_comments(1, :page => 1, :pageSize => 25)
45
+ end
46
46
  end
@@ -1,15 +1,15 @@
1
1
  require "helper"
2
2
 
3
3
  class TestUserFunctions < Test::Unit::TestCase
4
- def test_user
5
- fake_request(:get, "/users/test_user", :body => fixture("users/user_public"), :content_type => "application/json")
6
- user = @im_client.user("test_user")
7
- check_eh :user, user
8
- assert_respond_to user, :username
9
- assert_equal "test_user", user.username
10
- assert_respond_to user, :comments
11
- assert_equal 3, user.comments
12
- assert_respond_to user, :ratings
13
- assert_equal 3, user.ratings
14
- end
4
+ def test_user
5
+ fake_request(:get, "/users/test_user", :body => fixture("users/user_public"), :content_type => "application/json")
6
+ user = @im_client.user("test_user")
7
+ check_eh :user, user
8
+ assert_respond_to user, :username
9
+ assert_equal "test_user", user.username
10
+ assert_respond_to user, :comments
11
+ assert_equal 3, user.comments
12
+ assert_respond_to user, :ratings
13
+ assert_equal 3, user.ratings
14
+ end
15
15
  end
@@ -1,47 +1,55 @@
1
1
  require "helper"
2
2
 
3
3
  class TestUserMemeFunctions < Test::Unit::TestCase
4
- def test_library
5
- fake_request(:get, "/users/test_user/memes?page=1&pageSize=25&sort=date-asc", :body => fixture("users/memes"), :content_type => "application/json")
6
- authorize
7
- check_paged :memes, @im_client.library(:page => 1, :pageSize => 25, :sort => "date-asc", :no_extract => true)
8
- check_list :memes, @im_client.library(:page => 1, :pageSize => 25, :sort => "date-asc")
9
- end
4
+ def test_library
5
+ fake_request(:get, "/users/test_user/memes?page=1&pageSize=25&sort=date-asc", :body => fixture("users/memes"), :content_type => "application/json")
6
+ authorize
7
+ check_paged :memes, @im_client.library(:page => 1, :pageSize => 25, :sort => "date-asc", :no_extract => true)
8
+ check_list :memes, @im_client.library(:page => 1, :pageSize => 25, :sort => "date-asc")
9
+ end
10
10
 
11
- def test_published
12
- fake_request(:get, "/users/test_user/memes/published?page=1&pageSize=25&sort=date-asc", :body => fixture("users/memes"), :content_type => "application/json")
13
- authorize
14
- check_paged :memes, @im_client.published(:page => 1, :pageSize => 25, :sort => "date-asc", :no_extract => true)
15
- check_list :memes, @im_client.published(:page => 1, :pageSize => 25, :sort => "date-asc")
16
- end
11
+ def test_published
12
+ fake_request(:get, "/users/test_user/memes/published?page=1&pageSize=25&sort=date-asc", :body => fixture("users/memes"), :content_type => "application/json")
13
+ authorize
14
+ check_paged :memes, @im_client.published(:page => 1, :pageSize => 25, :sort => "date-asc", :no_extract => true)
15
+ check_list :memes, @im_client.published(:page => 1, :pageSize => 25, :sort => "date-asc")
16
+ end
17
17
 
18
- def test_inactive
19
- fake_request(:get, "/users/test_user/memes/inactive?page=1&pageSize=25&sort=date-asc", :body => fixture("users/memes"), :content_type => "application/json")
20
- authorize
21
- check_paged :memes, @im_client.inactive(:page => 1, :pageSize => 25, :sort => "date-asc", :no_extract => true)
22
- check_list :memes, @im_client.inactive(:page => 1, :pageSize => 25, :sort => "date-asc")
23
- end
18
+ def test_inactive
19
+ fake_request(:get, "/users/test_user/memes/inactive?page=1&pageSize=25&sort=date-asc", :body => fixture("users/memes"), :content_type => "application/json")
20
+ authorize
21
+ check_paged :memes, @im_client.inactive(:page => 1, :pageSize => 25, :sort => "date-asc", :no_extract => true)
22
+ check_list :memes, @im_client.inactive(:page => 1, :pageSize => 25, :sort => "date-asc")
23
+ end
24
24
 
25
- def test_incomplete
26
- fake_request(:get, "/users/test_user/memes/incomplete?page=1&pageSize=25&sort=date-asc", :body => fixture("users/memes"), :content_type => "application/json")
27
- authorize
28
- check_paged :memes, @im_client.incomplete(:page => 1, :pageSize => 25, :sort => "date-asc", :no_extract => true)
29
- check_list :memes, @im_client.incomplete(:page => 1, :pageSize => 25, :sort => "date-asc")
30
- end
25
+ def test_incomplete
26
+ fake_request(:get, "/users/test_user/memes/incomplete?page=1&pageSize=25&sort=date-asc", :body => fixture("users/memes"), :content_type => "application/json")
27
+ authorize
28
+ check_paged :memes, @im_client.incomplete(:page => 1, :pageSize => 25, :sort => "date-asc", :no_extract => true)
29
+ check_list :memes, @im_client.incomplete(:page => 1, :pageSize => 25, :sort => "date-asc")
30
+ end
31
31
 
32
- def test_comment
33
- fake_request(:post, "/users/test_user/memes/1/comments", :body => fixture("response/ok"), :content_type => "application/json")
34
- authorize
35
- assert_nothing_raised do
36
- assert @im_client.comment(1, "test comment")
37
- end
32
+ def test_comment
33
+ fake_request(:post, "/users/test_user/memes/1/comments", :body => fixture("response/ok"), :content_type => "application/json")
34
+ authorize
35
+ assert_nothing_raised do
36
+ assert @im_client.comment(1, "test comment")
38
37
  end
38
+ end
39
39
 
40
- def test_rate
41
- fake_request(:post, "/users/test_user/memes/1/rates", :body => fixture("response/ok"), :content_type => "application/json")
42
- authorize
43
- assert_nothing_raised do
44
- assert @im_client.rate(1, 1)
45
- end
40
+ def test_rate
41
+ fake_request(:post, "/users/test_user/memes/1/rates", :body => fixture("response/ok"), :content_type => "application/json")
42
+ authorize
43
+ assert_nothing_raised do
44
+ assert @im_client.rate(1, 1)
45
+ end
46
+ end
47
+
48
+ def test_review
49
+ fake_request(:post, "/user/test_user/memes/1/reviews", :body => fixture("response/ok"), :content_type => "application/json")
50
+ authorize
51
+ assert_nothing_raised do
52
+ assert @im_client.rate(1, {:rate => 1, :comment => "lajos"})
46
53
  end
54
+ end
47
55
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: infomeme_client
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.8
4
+ version: 0.2.10
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,12 +9,12 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2011-04-26 00:00:00.000000000 +02:00
12
+ date: 2011-06-09 00:00:00.000000000 +02:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: oauth
17
- requirement: &22466900 !ruby/object:Gem::Requirement
17
+ requirement: &21418220 !ruby/object:Gem::Requirement
18
18
  none: false
19
19
  requirements:
20
20
  - - ! '>='
@@ -22,10 +22,10 @@ dependencies:
22
22
  version: '0'
23
23
  type: :runtime
24
24
  prerelease: false
25
- version_requirements: *22466900
25
+ version_requirements: *21418220
26
26
  - !ruby/object:Gem::Dependency
27
27
  name: json
28
- requirement: &22466400 !ruby/object:Gem::Requirement
28
+ requirement: &21417700 !ruby/object:Gem::Requirement
29
29
  none: false
30
30
  requirements:
31
31
  - - ! '>='
@@ -33,10 +33,10 @@ dependencies:
33
33
  version: '0'
34
34
  type: :runtime
35
35
  prerelease: false
36
- version_requirements: *22466400
36
+ version_requirements: *21417700
37
37
  - !ruby/object:Gem::Dependency
38
38
  name: multipart-post
39
- requirement: &22465900 !ruby/object:Gem::Requirement
39
+ requirement: &21417160 !ruby/object:Gem::Requirement
40
40
  none: false
41
41
  requirements:
42
42
  - - ! '>='
@@ -44,10 +44,10 @@ dependencies:
44
44
  version: '0'
45
45
  type: :runtime
46
46
  prerelease: false
47
- version_requirements: *22465900
47
+ version_requirements: *21417160
48
48
  - !ruby/object:Gem::Dependency
49
49
  name: mime-types
50
- requirement: &22465400 !ruby/object:Gem::Requirement
50
+ requirement: &21416660 !ruby/object:Gem::Requirement
51
51
  none: false
52
52
  requirements:
53
53
  - - ! '>='
@@ -55,7 +55,7 @@ dependencies:
55
55
  version: '0'
56
56
  type: :runtime
57
57
  prerelease: false
58
- version_requirements: *22465400
58
+ version_requirements: *21416660
59
59
  description: ! "A RubyGem for implementing both Infomeme client and meme applications.\n
60
60
  More coming soon..."
61
61
  email: infomeme@infomeme.com
@@ -79,6 +79,7 @@ files:
79
79
  - lib/infomeme_client/entity_hash/invoice.rb
80
80
  - lib/infomeme_client/entity_hash/meme.rb
81
81
  - lib/infomeme_client/entity_hash/meme_type.rb
82
+ - lib/infomeme_client/entity_hash/review.rb
82
83
  - lib/infomeme_client/entity_hash/transaction.rb
83
84
  - lib/infomeme_client/entity_hash/user.rb
84
85
  - lib/infomeme_client/errors.rb