Class: FinerWorks::Client
- Inherits:
-
Object
- Object
- FinerWorks::Client
- Defined in:
- lib/finerworks/client.rb
Overview
The Client is the primary interface to the FinerWorks Web API.
Instance Attribute Summary collapse
-
#account_api_key ⇒ String
A FinerWorks account API key.
Instance Method Summary collapse
-
#account ⇒ Account
Provides account profile information.
- #build_post_account_json(account) ⇒ Object
-
#galleries ⇒ Array<Gallery>
Lists galleries (aka portfolios) under the current account.
-
#get(type, path, options = {}) ⇒ Array<Object>
Generic GET method to request items of the specified
type
. -
#images(options = {}) ⇒ Array<Image>
Lists images stored in My Images.
-
#initialize(options = {}) {|_self| ... } ⇒ Client
constructor
A new instance of Client.
-
#order_details(id) ⇒ Array<OrderDetails>
Provides details for a specific order.
-
#order_submission(num_carts = 1) ⇒ Array<Cart>
Sets up shopping carts that can be used to submit orders.
-
#orders(options = {}) ⇒ Array<Order>
Lists orders.
-
#prints(options = {}) ⇒ Array<Print>
Lists prints stored in My Prints Inventory.
-
#update_account(account) ⇒ Response
Updates account profile information.
Constructor Details
#initialize(options = {}) {|_self| ... } ⇒ Client
Returns a new instance of Client.
18 19 20 21 22 23 |
# File 'lib/finerworks/client.rb', line 18 def initialize( = {}) .each do |key, value| instance_variable_set("@#{key}", value) end yield(self) if block_given? end |
Instance Attribute Details
#account_api_key ⇒ String
A FinerWorks account API key.
15 16 17 |
# File 'lib/finerworks/client.rb', line 15 def account_api_key @account_api_key end |
Instance Method Details
#account ⇒ Account
Provides account profile information.
28 29 30 31 |
# File 'lib/finerworks/client.rb', line 28 def account result = FinerWorks::Request.get(self, "/Account") FinerWorks::Account.new(result.json) end |
#build_post_account_json(account) ⇒ Object
113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 |
# File 'lib/finerworks/client.rb', line 113 def build_post_account_json(account) { "AccountApiKey" => account_api_key, "AccountUsername" => account.username, "AccountUpdate_Info" => { "AccountEmail" => account.email, "AccountFirstName" => account.first_name, "AccountMiddleName" => account.middle_name, "AccountLastName" => account.last_name, "AccountPhone" => account.phone, "AccountBio" => account.bio, "AccountTitle" => account.title } } end |
#galleries ⇒ Array<Gallery>
Lists galleries (aka portfolios) under the current account.
54 55 56 |
# File 'lib/finerworks/client.rb', line 54 def galleries get(FinerWorks::Gallery, "/Galleries") end |
#get(type, path, options = {}) ⇒ Array<Object>
Generic GET method to request items of the specified type
. This always returns an Array
.
103 104 105 106 107 108 109 110 111 |
# File 'lib/finerworks/client.rb', line 103 def get(type, path, = {}) response = FinerWorks::Request.get(self, path, ) items = response.json.kind_of?(Array) ? response.json : [response.json] results = [] items.each do |item| results << type.new(item) end results end |
#images(options = {}) ⇒ Array<Image>
Lists images stored in My Images.
64 65 66 |
# File 'lib/finerworks/client.rb', line 64 def images( = {}) get(FinerWorks::Image, "/Images", ) end |
#order_details(id) ⇒ Array<OrderDetails>
Provides details for a specific order.
85 86 87 |
# File 'lib/finerworks/client.rb', line 85 def order_details(id) get(FinerWorks::OrderDetails, "/OrderDetails", { "OrderID" => id }) end |
#order_submission(num_carts = 1) ⇒ Array<Cart>
Sets up shopping carts that can be used to submit orders.
93 94 95 |
# File 'lib/finerworks/client.rb', line 93 def order_submission(num_carts = 1) get(FinerWorks::Cart, "/OrderSubmission", { "NewCart" => num_carts }) end |
#orders(options = {}) ⇒ Array<Order>
Lists orders.
77 78 79 |
# File 'lib/finerworks/client.rb', line 77 def orders( = {}) get(FinerWorks::Order, "/Orders", ) end |
#prints(options = {}) ⇒ Array<Print>
Lists prints stored in My Prints Inventory.
47 48 49 |
# File 'lib/finerworks/client.rb', line 47 def prints( = {}) get(FinerWorks::Print, "/Prints", ) end |
#update_account(account) ⇒ Response
Updates account profile information.
37 38 39 |
# File 'lib/finerworks/client.rb', line 37 def update_account(account) result = FinerWorks::Request.post(self, "/Account", build_post_account_json(account)) end |