class FinerWorks::Client
The Client
is the primary interface to the FinerWorks
Web API.
@attr [String] account_api_key
A FinerWorks
account API key.
Attributes
Public Class Methods
# File lib/finerworks/client.rb, line 18 def initialize(options = {}) options.each do |key, value| instance_variable_set("@#{key}", value) end yield(self) if block_given? end
Public Instance Methods
Provides account profile information.
@return [Account] Account
information. Returns the account associated with the client’s API key.
# File lib/finerworks/client.rb, line 28 def account result = FinerWorks::Request.get(self, "/Account") FinerWorks::Account.new(result.json) end
# 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
Lists galleries (aka portfolios) under the current account.
@return [Array<Gallery>] A list of galleries.
# File lib/finerworks/client.rb, line 54 def galleries get(FinerWorks::Gallery, "/Galleries") end
Generic GET method to request items of the specified type
. This always returns an Array
.
@param type [Class] Type of objects to return. @param path [String] API request path. @param [Hash] options Parameters to include in the request URI. @return [Array<Object>] A list of items.
# File lib/finerworks/client.rb, line 103 def get(type, path, options = {}) response = FinerWorks::Request.get(self, path, options) items = response.json.kind_of?(Array) ? response.json : [response.json] results = [] items.each do |item| results << type.new(item) end results end
Lists images stored in My Images.
@param [Hash] options Filtering/sorting options. @option options [String] “GalleryGUID” Find images that are under a specific gallery. @option options [String] “Sort” (“DESC”) Sort images by upload dates. Possible values are “ASC” or “DESC”. @return [Array<Image>] A list of images.
# File lib/finerworks/client.rb, line 64 def images(options = {}) get(FinerWorks::Image, "/Images", options) end
Sets up shopping carts that can be used to submit orders.
@param num_carts [Integer] Number of new carts to create (1-100). Default is 1. @return [Array<Cart>] New shopping cart(s).
# File lib/finerworks/client.rb, line 93 def order_submission(num_carts = 1) get(FinerWorks::Cart, "/OrderSubmission", { "NewCart" => num_carts }) end
Lists orders.
@param [Hash] options Filtering/sorting options. @option options [String] “OrderDateTime_Start” Find orders in the time period starting at the specified date/time. Acceptable formats include “MM/DD/YYYY” or “YYYY-MM-DD”. @option options [String] “OrderDateTime_End” Find orders in the time period ending at the specified date/time. Acceptable formats include “MM/DD/YYYY” or “YYYY-MM-DD”. @option options [String] “OrderStatusID” Find orders with a specific status. @option options [String] “OrderID” Find a specific order by order ID. @option options [String] “Sort” (“DESC”) Sort orders by ID. Possible values are “ASC” or “DESC”. @return [Array<Order>] A list of orders.
# File lib/finerworks/client.rb, line 77 def orders(options = {}) get(FinerWorks::Order, "/Orders", options) end
Lists prints stored in My Prints Inventory.
@param [Hash] options Filtering options. @option options [String] “ImageGUID” Find prints based on a specific image. @option options [String] “GalleryGUID” Find prints whose images are under a specific gallery. @return [Array<Print>] A list of prints.
# File lib/finerworks/client.rb, line 47 def prints(options = {}) get(FinerWorks::Print, "/Prints", options) end
Updates account profile information.
@param [Account] account Account
information. @return [Response] API response.
# File lib/finerworks/client.rb, line 37 def update_account(account) result = FinerWorks::Request.post(self, "/Account", build_post_account_json(account)) end