Class: Moo::Client
Instance Attribute Summary collapse
-
#oauth_access_token ⇒ Object
Returns the value of attribute oauth_access_token.
-
#oauth_consumer ⇒ Object
Returns the value of attribute oauth_consumer.
-
#oauth_consumer_key ⇒ Object
Returns the value of attribute oauth_consumer_key.
-
#oauth_consumer_secret ⇒ Object
Returns the value of attribute oauth_consumer_secret.
Class Method Summary collapse
- .config {|_self| ... } ⇒ Object
- .oauth_consumer_key=(key) ⇒ Object
- .oauth_consumer_secret=(secret) ⇒ Object
Instance Method Summary collapse
- #create_pack(pack) ⇒ Object
- #get_request_token(options) ⇒ Object
- #import_image(image_url) ⇒ Object
-
#initialize(options = {}) {|_self| ... } ⇒ Client
constructor
A new instance of Client.
- #update_pack(pack_id, pack) ⇒ Object
- #upload_image(path) ⇒ Object
Constructor Details
#initialize(options = {}) {|_self| ... } ⇒ Client
Returns a new instance of Client.
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/moo/client.rb', line 22 def initialize(={}) @oauth_consumer_secret = [:oauth_consumer_secret] @oauth_consumer_key = [:oauth_consumer_key] yield self if block_given? # set key/secret to default if not set @oauth_consumer_secret ||= @@oauth_consumer_secret @oauth_consumer_key ||= @@oauth_consumer_key # error if the oauth secret and key have not been set by now unless @oauth_consumer_secret and @oauth_consumer_key raise "Moo Client requires OAuth consumer key/secret" end # create the consumer @oauth_consumer = OAuth::Consumer.new( @oauth_consumer_key, @oauth_consumer_secret, { site: "https://secure.moo.com", request_token_path: "/oauth/request_token.php", access_token_path: "/oauth/access_token.php", authorize_path: "/oauth/authorize.php" }) # create the access token if [:oauth_access_token] and [:oauth_access_token_secret] @oauth_access_token = OAuth::AccessToken.new( @oauth_consumer, [:oauth_access_token], [:oauth_access_token_secret]) end end |
Instance Attribute Details
#oauth_access_token ⇒ Object
Returns the value of attribute oauth_access_token.
5 6 7 |
# File 'lib/moo/client.rb', line 5 def oauth_access_token @oauth_access_token end |
#oauth_consumer ⇒ Object
Returns the value of attribute oauth_consumer.
5 6 7 |
# File 'lib/moo/client.rb', line 5 def oauth_consumer @oauth_consumer end |
#oauth_consumer_key ⇒ Object
Returns the value of attribute oauth_consumer_key.
5 6 7 |
# File 'lib/moo/client.rb', line 5 def oauth_consumer_key @oauth_consumer_key end |
#oauth_consumer_secret ⇒ Object
Returns the value of attribute oauth_consumer_secret.
5 6 7 |
# File 'lib/moo/client.rb', line 5 def oauth_consumer_secret @oauth_consumer_secret end |
Class Method Details
.config {|_self| ... } ⇒ Object
18 19 20 |
# File 'lib/moo/client.rb', line 18 def self.config yield self if block_given? end |
.oauth_consumer_key=(key) ⇒ Object
14 15 16 |
# File 'lib/moo/client.rb', line 14 def self.oauth_consumer_key=(key) @@oauth_consumer_key = key end |
.oauth_consumer_secret=(secret) ⇒ Object
10 11 12 |
# File 'lib/moo/client.rb', line 10 def self.oauth_consumer_secret=(secret) @@oauth_consumer_secret = secret end |
Instance Method Details
#create_pack(pack) ⇒ Object
60 61 62 63 64 65 66 |
# File 'lib/moo/client.rb', line 60 def create_pack(pack) call({ method: "moo.pack.createPack", product: pack.product_code.to_s, pack: pack.to_json }) end |
#get_request_token(options) ⇒ Object
56 57 58 |
# File 'lib/moo/client.rb', line 56 def get_request_token() @oauth_consumer.get_request_token(oauth_callback: [:callback]) end |
#import_image(image_url) ⇒ Object
89 90 91 92 93 94 |
# File 'lib/moo/client.rb', line 89 def import_image(image_url) call({ method: "moo.image.importImage", imageUrl: image_url }) end |
#update_pack(pack_id, pack) ⇒ Object
68 69 70 71 72 73 74 |
# File 'lib/moo/client.rb', line 68 def update_pack(pack_id, pack) call({ method: "moo.pack.updatePack", packId: pack_id, pack: pack.to_json }) end |
#upload_image(path) ⇒ Object
76 77 78 79 80 81 82 83 84 85 86 87 |
# File 'lib/moo/client.rb', line 76 def upload_image(path) File.open(path) do |image| params = { method: "moo.image.uploadImage", imageFile: UploadIO.new(image, "image/jpeg", "image.jpg") } request = Net::HTTP::Post::Multipart.new("/api/service/", params) http = Net::HTTP.new("www.moo.com", 80) response = http.start {|net| net.request(request) } handle_response(response) end end |