finerworks 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: c3c4c9dc051625f149a4d8ee5ca48de3f13c92b7
4
+ data.tar.gz: d29862702db6a733cf04ec084949d98dde9b7519
5
+ SHA512:
6
+ metadata.gz: d25b11d9c70ccb35e4abbbd29fe078c97707a598e91e55bea23a6669f0bfe9d88baa7efbe9f95c044d3c28e0662d88bc40580bdd7aa1b05766a028f2fa383cfd
7
+ data.tar.gz: db84180174265d98f3a6f54baf09efe344ce4250c5746dc4657ac4ba5fb5c174164c8a33864c8e7002cad2654e1f1e24caf4915268969f421a067148bf1cd309
@@ -0,0 +1,3 @@
1
+ require 'hashie'
2
+ require 'finerworks/utilities'
3
+ require 'finerworks/client'
@@ -0,0 +1,29 @@
1
+ module FinerWorks
2
+ class Account < Hashie::Trash
3
+ property :business_company_name, from: "AccountBusinessCompanyName"
4
+ property :business_department, from: "AccountBusinessDepartment"
5
+ property :company_description, from: "AccountCompanyDescription"
6
+ property :business_website_url, from: "AccountBusinessWebsiteURL"
7
+ property :business_address1, from: "AccountBusinessAddress1"
8
+ property :business_address2, from: "AccountBusinessAddress2"
9
+ property :business_city, from: "AccountBusinessCity"
10
+ property :business_state, from: "AccountBusinessState"
11
+ property :business_country, from: "AccountBusinessCountry"
12
+ property :business_zip, from: "AccountBusinessZip"
13
+ property :business_phone, from: "AccountBusinessPhone"
14
+ property :business_fax, from: "AccountBusinessFax"
15
+ property :username, from: "AccountUsername"
16
+ property :registration_date, from: "AccountRegistrationDate", transform_with: lambda { |d| FinerWorks::Utilities.parse_api_time(d) }
17
+ property :email, from: "AccountEmail"
18
+ property :type, from: "AccountType"
19
+ property :first_name, from: "AccountFirstName"
20
+ property :middle_name, from: "AccountMiddleName"
21
+ property :last_name, from: "AccountLastName"
22
+ property :phone, from: "AccountPhone"
23
+ property :logo_file, from: "AccountLogoFile"
24
+ property :portrait_file, from: "AccountPortraitFile"
25
+ property :bio, from: "AccountBio"
26
+ property :title, from: "AccountTitle"
27
+ property :seller_paypal_email, from: "AccountSellerPayPalEmail"
28
+ end
29
+ end
@@ -0,0 +1,95 @@
1
+ require 'finerworks/request'
2
+ require 'finerworks/response'
3
+ require 'finerworks/account'
4
+ require 'finerworks/print'
5
+ require 'finerworks/gallery'
6
+ require 'finerworks/image'
7
+ require 'finerworks/order'
8
+
9
+ module FinerWorks
10
+ class Client
11
+ attr_accessor :account_api_key
12
+
13
+ def initialize(options = {})
14
+ options.each do |key, value|
15
+ instance_variable_set("@#{key}", value)
16
+ end
17
+ yield(self) if block_given?
18
+ end
19
+
20
+ # Provides account profile information.
21
+ def account
22
+ result = FinerWorks::Request.get(self, "/Account")
23
+ FinerWorks::Account.new(result.json)
24
+ end
25
+
26
+ # Updates account profile information.
27
+ def update_account(account)
28
+ result = FinerWorks::Request.post(self, "/Account", build_post_account_json(account))
29
+ end
30
+
31
+ # Lists prints stored in My Prints Inventory.
32
+ #
33
+ # ==== Options hash:
34
+ # ["ImageGUID"] Filter by image.
35
+ # ["GalleryGUID"] Filter by gallery.
36
+ def prints(options = {})
37
+ get(FinerWorks::Print, "/Prints", options)
38
+ end
39
+
40
+ # Lists galleries (aka portfolios) under the current account.
41
+ def galleries
42
+ get(FinerWorks::Gallery, "/Galleries")
43
+ end
44
+
45
+ # Lists images stored in My Images.
46
+ #
47
+ # ==== Options hash:
48
+ # ["GalleryGUID"] Filter by gallery.
49
+ # ["Sort"] Sort images by upload date in ascending or descending order. Possible values are "ASC" and "DESC".
50
+ # Default is descending.
51
+ def images(options = {})
52
+ get(FinerWorks::Image, "/Images", options)
53
+ end
54
+
55
+ # Lists orders
56
+ #
57
+ # ==== Options hash:
58
+ # ["OrderDateTime_Start"] Search for orders in the range starting at the specified date/time.
59
+ # ["OrderDateTime_End"] Search for orders in the range ending at the specified date/time.
60
+ # ["OrderStatusID"] Search for orders with a specific status.
61
+ # ["OrderID"] Find a specific order by ID.
62
+ # ["Sort"] Sort orders by ID in ascending or descending order. Possible values are "ASC" and "DESC". Default is
63
+ # descending.
64
+ def orders(options = {})
65
+ get(FinerWorks::Order, "/Orders", options)
66
+ end
67
+
68
+ # Generic GET method to request items of the specified +type+. This always returns an +Array+.
69
+ def get(type, path, options = {})
70
+ response = FinerWorks::Request.get(self, path, options)
71
+ items = response.json.kind_of?(Array) ? response.json : [response.json]
72
+ results = []
73
+ items.each do |item|
74
+ results << type.new(item)
75
+ end
76
+ results
77
+ end
78
+
79
+ def build_post_account_json(account)
80
+ {
81
+ "AccountApiKey" => account_api_key,
82
+ "AccountUsername" => account.username,
83
+ "AccountUpdate_Info" => {
84
+ "AccountEmail" => account.email,
85
+ "AccountFirstName" => account.first_name,
86
+ "AccountMiddleName" => account.middle_name,
87
+ "AccountLastName" => account.last_name,
88
+ "AccountPhone" => account.phone,
89
+ "AccountBio" => account.bio,
90
+ "AccountTitle" => account.title
91
+ }
92
+ }
93
+ end
94
+ end
95
+ end
@@ -0,0 +1,9 @@
1
+ module FinerWorks
2
+ class Gallery < Hashie::Trash
3
+ property :title, from: "GalleryTitle"
4
+ property :active, from: "GalleryActive", transform_with: lambda { |value| value == "True" }
5
+ property :guid, from: "GalleryGUID"
6
+
7
+ alias_method :active?, :active
8
+ end
9
+ end
@@ -0,0 +1,26 @@
1
+ module FinerWorks
2
+ class Image < Hashie::Trash
3
+ property :guid, from: "ImageGUID"
4
+ property :url, from: "ImageUrl"
5
+ property :url_thumbnail, from: "ImageUrl_Thumbnail"
6
+ property :original_file_name, from: "ImageOriginalFileName"
7
+ property :file_name, from: "ImageFileName"
8
+ property :date_added, from: "ImageDateAdded", transform_with: lambda { |d| FinerWorks::Utilities.parse_api_time(d) }
9
+ property :active, from: "ImageActive", transform_with: lambda { |value| value == "True" }
10
+ property :file_size, from: "ImageFileSize"
11
+ property :w, from: "ImageW"
12
+ property :h, from: "ImageH"
13
+ property :title, from: "ImageTitle"
14
+ property :date_updated, from: "ImageDateUpdated", transform_with: lambda { |d| FinerWorks::Utilities.parse_api_time(d) }
15
+ property :rank, from: "ImageRank"
16
+ property :order, from: "ImageOrder"
17
+ property :rating, from: "ImageRating"
18
+ property :description, from: "ImageDescription"
19
+ property :gallery_guid, from: "GalleryGUID"
20
+ property :gallery_title, from: "GalleryTitle"
21
+ property :gallery_active, from: "GalleryActive"
22
+
23
+ alias_method :active?, :active
24
+ alias_method :gallery_active?, :active
25
+ end
26
+ end
@@ -0,0 +1,10 @@
1
+ module FinerWorks
2
+ class Order < Hashie::Trash
3
+ property :id, from: "OrderID"
4
+ property :grand_total, from: "OrderGrandTotal"
5
+ property :date_time, from: "OrderDateTime", transform_with: lambda { |d| FinerWorks::Utilities.parse_api_time(d) }
6
+ property :drop_ship, from: "OrderDropShip"
7
+ property :status_id, from: "OrderStatusID"
8
+ property :status_label, from: "OrderStatusLabel"
9
+ end
10
+ end
@@ -0,0 +1,26 @@
1
+ module FinerWorks
2
+ class Print < Hashie::Trash
3
+ property :add_on_title, from: "AddOnTitle"
4
+ property :canvas_add_on_name, from: "CanvasAddOnName"
5
+ property :card_stock_name, from: "CardStockName"
6
+ property :card_style_name, from: "CardStyleName"
7
+ property :image_guid, from: "ImageGUID"
8
+ property :image_title, from: "ImageTitle"
9
+ property :media_name, from: "MediaName"
10
+ property :mounting_name, from: "MountingName"
11
+ property :date_added, from: "PrintDateAdded", transform_with: lambda { |d| FinerWorks::Utilities.parse_api_time(d) }
12
+ property :description, from: "PrintDescription"
13
+ property :guid, from: "PrintGUID"
14
+ property :media_id, from: "PrintMediaID"
15
+ property :minor_retouch, from: "PrintMinorRetouch"
16
+ property :mounting_id, from: "PrintMountingID"
17
+ property :preview_file, from: "PrintPreviewFile"
18
+ property :product_preview_file, from: "PrintProductPreviewFile"
19
+ property :sale_price, from: "PrintSalePrice"
20
+ property :shipping_additional_price, from: "PrintShippingAdditionalPrice"
21
+ property :shipping_base_price, from: "PrintShippingBasePrice"
22
+ property :title, from: "PrintTitle"
23
+ property :gallery_guid, from: "GalleryGUID"
24
+ property :thumbnail_url, from: "PrintThumbnailUrl"
25
+ end
26
+ end
@@ -0,0 +1,32 @@
1
+ require 'uri'
2
+ require 'net/http'
3
+
4
+ module FinerWorks
5
+ class Request
6
+ BASE_URL = "http://api.finerworks.com/api"
7
+
8
+ def self.get(client, path, options = {})
9
+ path.prepend("/") if !path.start_with?("/")
10
+ params = ""
11
+ options.each do |option|
12
+ params = params + "&#{option[0].to_s}=#{option[1]}"
13
+ end
14
+ uri = URI.parse("#{BASE_URL}#{path}?AccountApiKey=#{client.account_api_key}#{params}")
15
+ http = Net::HTTP.new(uri.host, uri.port)
16
+ request = Net::HTTP::Get.new(uri.request_uri)
17
+ response = http.request(request)
18
+ FinerWorks::Response.new(response)
19
+ end
20
+
21
+ def self.post(client, path, options = {})
22
+ path.prepend("/") if !path.start_with?("/")
23
+ uri = URI.parse("#{BASE_URL}#{path}?AccountApiKey=#{client.account_api_key}")
24
+ http = Net::HTTP.new(uri.host, uri.port)
25
+ request = Net::HTTP::Post.new(uri.request_uri)
26
+ request.body = options.to_json
27
+ request.content_type = "application/json"
28
+ response = http.request(request)
29
+ FinerWorks::Response.new(response)
30
+ end
31
+ end
32
+ end
@@ -0,0 +1,14 @@
1
+ require 'json'
2
+
3
+ module FinerWorks
4
+ class Response
5
+ attr_accessor :body, :json, :code, :message
6
+
7
+ def initialize(http_response)
8
+ @code = http_response.code
9
+ @message = http_response.message
10
+ @body = http_response.body
11
+ @json = JSON.parse(@body)
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,13 @@
1
+ require 'time'
2
+
3
+ module FinerWorks
4
+ module Utilities
5
+ module_function
6
+
7
+ # Parse ISO 8601 time strings from the FinerWorks Web API. This function takes into consideration the fact that
8
+ # the FinerWorks API does not specify a time zone in its responses, yet it appears to use US Central Time.
9
+ def parse_api_time(time_string)
10
+ Time.parse(time_string.split("T").first + "T00:00:00-0600")
11
+ end
12
+ end
13
+ end
metadata ADDED
@@ -0,0 +1,125 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: finerworks
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Jeff Fredrickson
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-09-18 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: json
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.4'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.4'
27
+ - !ruby/object:Gem::Dependency
28
+ name: hashie
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '3.4'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '3.4'
41
+ - !ruby/object:Gem::Dependency
42
+ name: minitest
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '5.8'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '5.8'
55
+ - !ruby/object:Gem::Dependency
56
+ name: webmock
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '1.21'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '1.21'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rake
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '10.0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '10.0'
83
+ description: This gem wraps the FinerWorks Web API in order to provide an easy way
84
+ to utilize the API in Ruby apps.
85
+ email:
86
+ - jeff.fredrickson@gmail.com
87
+ executables: []
88
+ extensions: []
89
+ extra_rdoc_files: []
90
+ files:
91
+ - lib/finerworks.rb
92
+ - lib/finerworks/account.rb
93
+ - lib/finerworks/client.rb
94
+ - lib/finerworks/gallery.rb
95
+ - lib/finerworks/image.rb
96
+ - lib/finerworks/order.rb
97
+ - lib/finerworks/print.rb
98
+ - lib/finerworks/request.rb
99
+ - lib/finerworks/response.rb
100
+ - lib/finerworks/utilities.rb
101
+ homepage: https://github.com/jfredrickson/finerworks
102
+ licenses:
103
+ - MIT
104
+ metadata: {}
105
+ post_install_message:
106
+ rdoc_options: []
107
+ require_paths:
108
+ - lib
109
+ required_ruby_version: !ruby/object:Gem::Requirement
110
+ requirements:
111
+ - - ">="
112
+ - !ruby/object:Gem::Version
113
+ version: '0'
114
+ required_rubygems_version: !ruby/object:Gem::Requirement
115
+ requirements:
116
+ - - ">="
117
+ - !ruby/object:Gem::Version
118
+ version: '0'
119
+ requirements: []
120
+ rubyforge_project:
121
+ rubygems_version: 2.4.5.1
122
+ signing_key:
123
+ specification_version: 4
124
+ summary: Ruby interface for the FinerWorks Web API
125
+ test_files: []