Class: FinerWorks::Client

Inherits:
Object
  • Object
show all
Defined in:
lib/finerworks/client.rb

Overview

The Client is the primary interface to the FinerWorks Web API.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) {|_self| ... } ⇒ Client

Returns a new instance of Client.

Yields:

  • (_self)

Yield Parameters:



18
19
20
21
22
23
# 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

Instance Attribute Details

#account_api_keyString

A FinerWorks account API key.

Returns:

  • (String)

    the current value of account_api_key



15
16
17
# File 'lib/finerworks/client.rb', line 15

def 
  @account_api_key
end

Instance Method Details

#accountAccount

Provides account profile information.

Returns:

  • (Account)

    Account information. Returns the account associated with the client’s API key.



28
29
30
31
# File 'lib/finerworks/client.rb', line 28

def 
  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 ()
  {
    "AccountApiKey" => ,
    "AccountUsername" => .username,
    "AccountUpdate_Info" => {
      "AccountEmail" => .email,
      "AccountFirstName" => .first_name,
      "AccountMiddleName" => .middle_name,
      "AccountLastName" => .last_name,
      "AccountPhone" => .phone,
      "AccountBio" => .bio,
      "AccountTitle" => .title
    }
  }
end

#galleriesArray<Gallery>

Lists galleries (aka portfolios) under the current account.

Returns:

  • (Array<Gallery>)

    A list of galleries.



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.

Parameters:

  • type (Class)

    Type of objects to return.

  • path (String)

    API request path.

  • options (Hash) (defaults to: {})

    Parameters to include in the request URI.

Returns:

  • (Array<Object>)

    A list of items.



103
104
105
106
107
108
109
110
111
# 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

#images(options = {}) ⇒ Array<Image>

Lists images stored in My Images.

Parameters:

  • options (Hash) (defaults to: {})

    Filtering/sorting options.

Options Hash (options):

  • "GalleryGUID" (String)

    Find images that are under a specific gallery.

  • "Sort" (String) — default: "DESC"

    Sort images by upload dates. Possible values are “ASC” or “DESC”.

Returns:

  • (Array<Image>)

    A list of images.



64
65
66
# File 'lib/finerworks/client.rb', line 64

def images(options = {})
  get(FinerWorks::Image, "/Images", options)
end

#order_details(id) ⇒ Array<OrderDetails>

Provides details for a specific order.

Parameters:

  • id (Integer)

    Order ID number.

Returns:

  • (Array<OrderDetails>)

    Order details for the given order ID.



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.

Parameters:

  • num_carts (Integer) (defaults to: 1)

    Number of new carts to create (1-100). Default is 1.

Returns:

  • (Array<Cart>)

    New shopping cart(s).



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.

Parameters:

  • options (Hash) (defaults to: {})

    Filtering/sorting options.

Options Hash (options):

  • "OrderDateTime_Start" (String)

    Find orders in the time period starting at the specified date/time. Acceptable formats include “MM/DD/YYYY” or “YYYY-MM-DD”.

  • "OrderDateTime_End" (String)

    Find orders in the time period ending at the specified date/time. Acceptable formats include “MM/DD/YYYY” or “YYYY-MM-DD”.

  • "OrderStatusID" (String)

    Find orders with a specific status.

  • "OrderID" (String)

    Find a specific order by order ID.

  • "Sort" (String) — default: "DESC"

    Sort orders by ID. Possible values are “ASC” or “DESC”.

Returns:

  • (Array<Order>)

    A list of orders.



77
78
79
# File 'lib/finerworks/client.rb', line 77

def orders(options = {})
  get(FinerWorks::Order, "/Orders", options)
end

#prints(options = {}) ⇒ Array<Print>

Lists prints stored in My Prints Inventory.

Parameters:

  • options (Hash) (defaults to: {})

    Filtering options.

Options Hash (options):

  • "ImageGUID" (String)

    Find prints based on a specific image.

  • "GalleryGUID" (String)

    Find prints whose images are under a specific gallery.

Returns:

  • (Array<Print>)

    A list of prints.



47
48
49
# File 'lib/finerworks/client.rb', line 47

def prints(options = {})
  get(FinerWorks::Print, "/Prints", options)
end

#update_account(account) ⇒ Response

Updates account profile information.

Parameters:

  • account (Account)

    Account information.

Returns:



37
38
39
# File 'lib/finerworks/client.rb', line 37

def ()
  result = FinerWorks::Request.post(self, "/Account", ())
end