infomeme_client 0.1.2 → 0.1.3
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.
- data/Rakefile +1 -0
- data/VERSION +1 -1
- data/lib/infomeme_client.rb +1 -0
- data/lib/infomeme_client/entity_hash/invoice.rb +2 -0
- data/lib/infomeme_client/entity_hash/transaction.rb +0 -1
- data/lib/infomeme_client/functions/user.rb +25 -0
- data/lib/infomeme_client/functions/user_meme.rb +34 -15
- data/lib/infomeme_client/functions/user_transaction.rb +5 -10
- data/lib/infomeme_client/meme_application.rb +4 -4
- data/lib/infomeme_client/response.rb +2 -1
- metadata +19 -4
data/Rakefile
CHANGED
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.1.
|
1
|
+
0.1.3
|
data/lib/infomeme_client.rb
CHANGED
@@ -42,6 +42,31 @@ module InfomemeClient::Functions::User
|
|
42
42
|
handle_response :put, "/users/#{user_id || verified_user}/new_password", {:new_password => new_password}.merge(user_id.nil? ? {} : {:confirm_code => confirm_code})
|
43
43
|
end
|
44
44
|
|
45
|
+
def accept_tos
|
46
|
+
return false unless authorized?
|
47
|
+
handle_response :put, "/users/#{verified_user}/accept_tos" do
|
48
|
+
refresh_settings and return true
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
def countries
|
53
|
+
handle_response :get, "/users/countries" do |resp|
|
54
|
+
resp.countries unless resp.error?
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
def currencies
|
59
|
+
handle_response :get, "/users/currencies" do |resp|
|
60
|
+
resp.currencies unless resp.error?
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
def languages
|
65
|
+
handle_response :get, "/users/languages" do |resp|
|
66
|
+
resp.languages unless resp.error?
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
45
70
|
private
|
46
71
|
attr_accessor :settings
|
47
72
|
|
@@ -21,12 +21,23 @@ module InfomemeClient::Functions::UserMeme
|
|
21
21
|
|
22
22
|
def publish(meme_type, options = {})
|
23
23
|
return false unless can_publish?
|
24
|
-
|
24
|
+
skip_upload = options.key?(:skip_upload) && options[:skip_upload]
|
25
|
+
options[:image] = upload_image(options[:image]) if ! skip_upload && options.key?(:image) && ! options[:image].nil? && options[:image] != ""
|
26
|
+
meme_type = meme_type.id if meme_type.is_a?(InfomemeClient::EntityHash::MemeType)
|
27
|
+
meme_id = handle_response :post, "/users/#{verified_user}/memes", options.reject {|k,v| k == :file}.merge({:type => meme_type}) do |resp|
|
25
28
|
resp.meme_id unless resp.error?
|
26
29
|
end
|
30
|
+
upload(meme_id, options[:file]) if options.key?(:file)
|
31
|
+
meme_id
|
32
|
+
end
|
33
|
+
|
34
|
+
def published_meme(meme_id)
|
35
|
+
return false unless authorized?
|
36
|
+
extract_from_response :meme, :get, "/users/#{verified_user}/memes/#{meme_id}"
|
27
37
|
end
|
28
38
|
|
29
39
|
def update_meme(meme_id, options = {})
|
40
|
+
options[:image] = upload_image(options[:image]) if options.key?(:image)
|
30
41
|
meme_function meme_id, :put, nil, options
|
31
42
|
end
|
32
43
|
|
@@ -49,25 +60,27 @@ module InfomemeClient::Functions::UserMeme
|
|
49
60
|
def upload_for_meme(meme_id, raw = false)
|
50
61
|
return false unless authorized?
|
51
62
|
handle_response :get, "/users/#{verified_user}/memes/#{meme_id}/upload_url" do |resp|
|
52
|
-
(raw ?
|
63
|
+
(raw ? resp.upload_url : finalize_get_url(resp.upload_url, generate_signature.merge(:meme_id => meme_id))) unless resp.error?
|
53
64
|
end
|
54
65
|
end
|
55
66
|
|
56
|
-
def
|
57
|
-
upload_url = upload_for_meme(meme_id, true)
|
58
|
-
http_multipart(upload_url, generate_signature.merge({:meme_id => meme_id, :file => file})) if upload_url
|
59
|
-
end
|
60
|
-
|
61
|
-
def image_upload_for_meme(meme_id)
|
67
|
+
def image_upload_for_memes
|
62
68
|
return false unless authorized?
|
63
|
-
handle_response :get, "/users/#{verified_user}/memes
|
69
|
+
handle_response :get, "/users/#{verified_user}/memes/image_upload_parameters" do |resp|
|
64
70
|
resp.image_upload_parameters unless resp.error?
|
65
71
|
end
|
66
72
|
end
|
67
73
|
|
68
|
-
def
|
69
|
-
|
70
|
-
|
74
|
+
def upload(meme_id, file)
|
75
|
+
file = File.new(file) if file.is_a?(String)
|
76
|
+
upload_url = upload_for_meme(meme_id, true)
|
77
|
+
http_multipart(upload_url, generate_signature.merge({:meme_id => meme_id, :file => uploadio(file)})) if upload_url
|
78
|
+
end
|
79
|
+
|
80
|
+
def upload_image(file)
|
81
|
+
file = File.new(file) if file.is_a?(String)
|
82
|
+
upload_params = image_upload_for_memes
|
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)
|
71
84
|
end
|
72
85
|
|
73
86
|
def rate(meme_id, rating)
|
@@ -84,7 +97,7 @@ module InfomemeClient::Functions::UserMeme
|
|
84
97
|
def generate_signature
|
85
98
|
nonce = OAuth::Helper.generate_nonce
|
86
99
|
timestamp = Time.now.to_i
|
87
|
-
req_proxy = OAuth::RequestProxy.proxy("method" => "GET", "uri" =>
|
100
|
+
req_proxy = OAuth::RequestProxy.proxy("method" => "GET", "uri" => "https://api.infomeme.com", "parameters" => {"oauth_consumer_key" => consumer.key, "oauth_token" => token.token, "oauth_nonce" => nonce, "oauth_timestamp" => timestamp, "oauth_signature_method" => "HMAC-SHA1"})
|
88
101
|
signature = req_proxy.sign({:consumer_secret => consumer.secret, :token_secret => token.secret})
|
89
102
|
{:oauth_token => token.token, :oauth_nonce => nonce, :oauth_timestamp => timestamp, :oauth_signature => signature}
|
90
103
|
end
|
@@ -102,7 +115,13 @@ module InfomemeClient::Functions::UserMeme
|
|
102
115
|
def http_multipart(url, params)
|
103
116
|
url = URI.parse(url)
|
104
117
|
req = Net::HTTP::Post::Multipart.new url.path, params
|
105
|
-
|
106
|
-
|
118
|
+
http = Net::HTTP.new(url.host, url.port)
|
119
|
+
http.use_ssl = url.scheme == "https"
|
120
|
+
resp = http.start {|http| http.request(req)}
|
121
|
+
resp.is_a?(Net::HTTPSuccess)
|
122
|
+
end
|
123
|
+
|
124
|
+
def uploadio(file)
|
125
|
+
UploadIO.new(file, MIME::Types.type_for(file.path), file.path)
|
107
126
|
end
|
108
127
|
end
|
@@ -4,18 +4,13 @@ module InfomemeClient::Functions::UserTransaction
|
|
4
4
|
extract_or_response :transactions, :get, "/users/#{verified_user}/transactions", options
|
5
5
|
end
|
6
6
|
|
7
|
-
def transaction(transaction_id)
|
8
|
-
return false unless authorized?
|
9
|
-
extract_from_response :transaction, :get, "/users/#{verified_user}/transactions/#{transaction_id}"
|
10
|
-
end
|
11
|
-
|
12
7
|
def invoices(options = {})
|
13
|
-
|
14
|
-
|
8
|
+
return false unless authorized?
|
9
|
+
extract_or_response :invoices, :get, "/users/#{verified_user}/invoices", options
|
15
10
|
end
|
16
11
|
|
17
|
-
def invoice(
|
18
|
-
|
19
|
-
|
12
|
+
def invoice(invoice_id)
|
13
|
+
return false unless authorized?
|
14
|
+
extract_from_response :invoice, :get, "/users/#{verified_user}/invoices/#{invoice_id}"
|
20
15
|
end
|
21
16
|
end
|
@@ -4,12 +4,12 @@ class InfomemeClient::MemeApplication
|
|
4
4
|
self.token = OAuth::AccessToken.new(consumer)
|
5
5
|
end
|
6
6
|
|
7
|
-
def verify_access(meme_id, oauth_token, oauth_nonce, oauth_timestamp, oauth_signature)
|
8
|
-
handle_response :post, "/meme_app/verify_access", {:meme_id => meme_id, :verify_token => oauth_token, :verify_nonce => oauth_nonce, :verify_timestamp => oauth_timestamp, :verify_signature => oauth_signature}
|
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
9
|
end
|
10
10
|
|
11
|
-
def
|
12
|
-
handle_response :put, "/meme_app/
|
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
13
|
end
|
14
14
|
|
15
15
|
private
|
@@ -42,7 +42,8 @@ class InfomemeClient::Response < InfomemeClient::EntityHash
|
|
42
42
|
when :meme, :memes then InfomemeClient::EntityHash::Meme
|
43
43
|
when :meme_types then InfomemeClient::EntityHash::MemeType
|
44
44
|
when :user then InfomemeClient::EntityHash::User
|
45
|
-
when :
|
45
|
+
when :transactions then InfomemeClient::EntityHash::Transaction
|
46
|
+
when :invoice, :invoices then InfomemeClient::EntityHash::Invoice
|
46
47
|
else InfomemeClient::EntityHash
|
47
48
|
end
|
48
49
|
stored = to_hash[key]
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: infomeme_client
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 29
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 1
|
9
|
-
-
|
10
|
-
version: 0.1.
|
9
|
+
- 3
|
10
|
+
version: 0.1.3
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Infomeme Ltd.
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2010-
|
18
|
+
date: 2010-08-11 00:00:00 +02:00
|
19
19
|
default_executable:
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|
@@ -60,6 +60,20 @@ dependencies:
|
|
60
60
|
version: "0"
|
61
61
|
type: :runtime
|
62
62
|
version_requirements: *id003
|
63
|
+
- !ruby/object:Gem::Dependency
|
64
|
+
name: mime-types
|
65
|
+
prerelease: false
|
66
|
+
requirement: &id004 !ruby/object:Gem::Requirement
|
67
|
+
none: false
|
68
|
+
requirements:
|
69
|
+
- - ">="
|
70
|
+
- !ruby/object:Gem::Version
|
71
|
+
hash: 3
|
72
|
+
segments:
|
73
|
+
- 0
|
74
|
+
version: "0"
|
75
|
+
type: :runtime
|
76
|
+
version_requirements: *id004
|
63
77
|
description: A RubyGem for implementing both Infomeme client and meme applications.
|
64
78
|
email: infomeme@infomeme.com
|
65
79
|
executables: []
|
@@ -81,6 +95,7 @@ files:
|
|
81
95
|
- lib/infomeme_client/communication.rb
|
82
96
|
- lib/infomeme_client/entity_hash.rb
|
83
97
|
- lib/infomeme_client/entity_hash/comment.rb
|
98
|
+
- lib/infomeme_client/entity_hash/invoice.rb
|
84
99
|
- lib/infomeme_client/entity_hash/meme.rb
|
85
100
|
- lib/infomeme_client/entity_hash/meme_type.rb
|
86
101
|
- lib/infomeme_client/entity_hash/transaction.rb
|