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.
-
#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.
17 18 19 20 21 22 |
# File 'lib/finerworks/client.rb', line 17 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.
14 15 16 |
# File 'lib/finerworks/client.rb', line 14 def account_api_key @account_api_key end |
Instance Method Details
#account ⇒ Account
Provides account profile information.
27 28 29 30 |
# File 'lib/finerworks/client.rb', line 27 def account result = FinerWorks::Request.get(self, "/Account") FinerWorks::Account.new(result.json) end |
#build_post_account_json(account) ⇒ Object
104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 |
# File 'lib/finerworks/client.rb', line 104 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.
53 54 55 |
# File 'lib/finerworks/client.rb', line 53 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
.
94 95 96 97 98 99 100 101 102 |
# File 'lib/finerworks/client.rb', line 94 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.
63 64 65 |
# File 'lib/finerworks/client.rb', line 63 def images( = {}) get(FinerWorks::Image, "/Images", ) end |
#order_details(id) ⇒ Array<OrderDetails>
Provides details for a specific order.
84 85 86 |
# File 'lib/finerworks/client.rb', line 84 def order_details(id) get(FinerWorks::OrderDetails, "/OrderDetails", { "OrderID" => id }) end |
#orders(options = {}) ⇒ Array<Order>
Lists orders.
76 77 78 |
# File 'lib/finerworks/client.rb', line 76 def orders( = {}) get(FinerWorks::Order, "/Orders", ) end |
#prints(options = {}) ⇒ Array<Print>
Lists prints stored in My Prints Inventory.
46 47 48 |
# File 'lib/finerworks/client.rb', line 46 def prints( = {}) get(FinerWorks::Print, "/Prints", ) end |
#update_account(account) ⇒ Response
Updates account profile information.
36 37 38 |
# File 'lib/finerworks/client.rb', line 36 def update_account(account) result = FinerWorks::Request.post(self, "/Account", build_post_account_json(account)) end |