fetchapp-api-ruby 1.2.4

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,21 @@
1
+ v.1.2.4 Removed dependency on ActiveRecord and Active Support
2
+
3
+ v.1.2.3 Invalid Path
4
+
5
+ v.1.2.2 Pull request
6
+
7
+ v.1.2.1 Rename for legal reasons
8
+
9
+ v.0.9.2 Prelim RDoc complete; misc fixes to all classes
10
+
11
+ v.0.9.1 Prelim BETA
12
+
13
+ v.0.9 Item Support
14
+
15
+ v.0.2.2 Order support
16
+
17
+ v.0.2.1 Prelim rework
18
+
19
+ v.0.2 Functionality for Downloads and Account
20
+
21
+ v.0.1 Functionality for Orders and Items
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License
2
+
3
+ Copyright (c) <year> <copyright holders>
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
@@ -0,0 +1,13 @@
1
+ CHANGELOG
2
+ fetchapp-api-ruby.gemspec
3
+ init.rb
4
+ lib/fetchapp-api-ruby/account.rb
5
+ lib/fetchapp-api-ruby/base.rb
6
+ lib/fetchapp-api-ruby/download.rb
7
+ lib/fetchapp-api-ruby/item.rb
8
+ lib/fetchapp-api-ruby/order.rb
9
+ lib/fetchapp-api-ruby-ruby.rb
10
+ LICENSE
11
+ Manifest
12
+ Rakefile
13
+ README.md
@@ -0,0 +1,55 @@
1
+ # Installation from RubyGems.org
2
+ gem install fetchapp-api-ruby
3
+
4
+
5
+ # Setup
6
+ ```ruby
7
+ FetchAPI::Base.basic_auth('youraccount.fetchapp.com', 'demokey', 'demotoken')
8
+ ```
9
+ # Account
10
+ ```ruby
11
+ account = FetchAPI::Account.details
12
+
13
+ token = FetchAPI::Account.new_token *Subsequent calls will use the new token automatically
14
+ ```
15
+ # Downloads
16
+ ```ruby
17
+ downloads = FetchAPI::Download.find(:all, :per_page => 50, :page => 2)
18
+
19
+ download = FetchAPI::Download.find(1)
20
+ ```
21
+
22
+ # Items
23
+ ```ruby
24
+ items = FetchAPI::Item.find(:all, :per_page => 10, :page => 3)
25
+
26
+ item = FetchAPI::Item.find("CJ0001")
27
+
28
+ item = FetchAPI::Item.create(:sku => "CJ0001", :name => "Carrot Juice")
29
+
30
+ item.update(:name => "Tomato Juice")
31
+
32
+ item.destroy
33
+
34
+ downloads = item.downloads *Returns an array of FetchAPI::Downloads for this item
35
+ ```
36
+ # Orders
37
+ ```ruby
38
+ all_orders = FetchAPI::Order.find(:all)
39
+
40
+ current_orders = FetchAPI::Order.find(:current, :page => 3)
41
+
42
+ manual_orders = FetchAPI::Order.find(:manual, :per_page => 10)
43
+
44
+ expired_orders = FetchAPI::Order.find(:expired, :per_page => 10, :page => 3)
45
+
46
+ order = FetchAPI::Order.find("1001")
47
+
48
+ order = FetchAPI::Order.create(:id => "1015", :title => "Test Order", :first_name => "Donald", :last_name => "Duck", :email => "donald@duck.com", :order_items => [{:sku => 'ABC0001'}, {:sku => 'ABC0002}])
49
+
50
+ order.update(:first_name => "Daffy")
51
+
52
+ order.destroy
53
+
54
+ downloads = order.downloads *Returns an array of FetchAPI::Downloads for this order
55
+ ```
File without changes
@@ -0,0 +1,33 @@
1
+ # -*- encoding: utf-8 -*-
2
+
3
+ Gem::Specification.new do |s|
4
+ s.name = %q{fetchapp-api-ruby}
5
+ s.version = "1.2.4"
6
+
7
+ s.required_rubygems_version = Gem::Requirement.new(">= 1.2") if s.respond_to? :required_rubygems_version=
8
+ s.authors = ["Michael Larkin"]
9
+ s.date = Date.today.strftime('%Y-%m-%d')
10
+ s.description = %q{Integrate your site with http://fetchapp.com for seamless digital delivery.}
11
+ s.email = %q{support@fetchapp.com}
12
+ s.extra_rdoc_files = ["CHANGELOG", "lib/fetchapp-api-ruby/account.rb", "lib/fetchapp-api-ruby/base.rb", "lib/fetchapp-api-ruby/download.rb", "lib/fetchapp-api-ruby/item.rb", "lib/fetchapp-api-ruby/order.rb", "lib/fetchapp-api-ruby.rb", "LICENSE", "README.md"]
13
+ s.files = ["CHANGELOG", "fetchapp-api-ruby.gemspec", "init.rb", "lib/fetchapp-api-ruby/account.rb", "lib/fetchapp-api-ruby/base.rb", "lib/fetchapp-api-ruby/download.rb", "lib/fetchapp-api-ruby/item.rb", "lib/fetchapp-api-ruby/order.rb", "lib/fetchapp-api-ruby.rb", "LICENSE", "Manifest", "Rakefile", "README.md"]
14
+ s.has_rdoc = true
15
+ s.homepage = %q{http://github.com/getsy/fetchapp-api-ruby}
16
+ s.rdoc_options = ["--line-numbers", "--inline-source", "--title", "fetchapp-api-ruby", "--main", "README.md"]
17
+ s.require_paths = ["lib"]
18
+ s.rubygems_version = %q{1.3.1}
19
+ s.summary = %q{This Ruby library allows you to integrate your site with http://fetchapp.com for seamless digital delivery so you can build additional functionality while retaining the core features of Fetch. Credit for the bulk of the code goes to Thomas Reynolds.}
20
+
21
+ if s.respond_to? :specification_version then
22
+ current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
23
+ s.specification_version = 2
24
+
25
+ if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
26
+ s.add_runtime_dependency(%q<httparty>, [">= 0"])
27
+ else
28
+ s.add_dependency(%q<httparty>, [">= 0"])
29
+ end
30
+ else
31
+ s.add_dependency(%q<httparty>, [">= 0"])
32
+ end
33
+ end
data/init.rb ADDED
@@ -0,0 +1 @@
1
+ require File.join(File.dirname(__FILE__), 'lib', 'fetchapp-api-ruby')
@@ -0,0 +1,10 @@
1
+ require 'rubygems'
2
+ require 'httparty'
3
+ require 'net/http'
4
+
5
+ $:.unshift(File.dirname(__FILE__))
6
+ require 'fetchapp-api-ruby/base'
7
+ require 'fetchapp-api-ruby/account'
8
+ require 'fetchapp-api-ruby/download'
9
+ require 'fetchapp-api-ruby/item'
10
+ require 'fetchapp-api-ruby/order'
@@ -0,0 +1,26 @@
1
+ module FetchAPI
2
+ class Account < FetchAPI::Base
3
+ attr_accessor :attributes
4
+ #--
5
+ ################ Class Methods ###############
6
+ #--
7
+
8
+ # Retrieves information about the Account
9
+ def self.details
10
+ account = Account.new({})
11
+ account.attributes = execute(:get, "/account")["account"]
12
+ account
13
+ end
14
+
15
+ # Generates a new API token. Subsequent API calls using the
16
+ # existing token will be refused.
17
+ def self.new_token
18
+ token = execute(:get, "/new_token")
19
+ unless token["message"].nil? || token["message"].empty?
20
+ # Reauthorize
21
+ Connector.basic_auth(FetchAPI::Base.key, token["message"])
22
+ token
23
+ end
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,103 @@
1
+ module FetchAPI
2
+ class Base
3
+ require 'pp'
4
+
5
+ def initialize(id_or_attributes) #:nodoc:
6
+ case id_or_attributes
7
+ when Integer, String
8
+ @attributes = get("/#{self.class.pluralized_class_name}/#{id_or_attributes.to_s}")
9
+ @attributes = @attributes[self.class.singularized_class_name]
10
+ @id = @attributes['id']
11
+ when Hash
12
+ @attributes = id_or_attributes
13
+ @id = id_or_attributes['id']
14
+ end
15
+ end
16
+
17
+ def self.find(selector, params={}) #:nodoc:
18
+ case selector
19
+ when :all
20
+ objects = execute(:get, "/#{pluralized_class_name}", params)
21
+
22
+ if objects[pluralized_class_name].nil? || objects[pluralized_class_name].empty?
23
+ return []
24
+ else
25
+ objects[pluralized_class_name].map { |data| new(data) }
26
+ end
27
+ when Integer, String
28
+ new(selector)
29
+ end
30
+ end
31
+
32
+ class Connector #:nodoc:
33
+ include HTTParty
34
+ format :xml
35
+ end
36
+
37
+ # Initializes the connection to the API
38
+ def self.basic_auth(url, key, token)
39
+ @key = key # Save this in case they generate a new token later
40
+ Connector.base_uri(url+"/api")
41
+ Connector.basic_auth(key, token)
42
+ end
43
+
44
+ def self.key #:nodoc:
45
+ return @key
46
+ end
47
+
48
+ protected
49
+ def self.singularized_class_name #:nodoc:
50
+ ancestors.first.to_s.split('::').last.downcase
51
+ end
52
+
53
+ def self.pluralized_class_name #:nodoc:
54
+ ancestors.first.to_s.split('::').last.downcase << 's'
55
+ end
56
+
57
+ def post(*args) #:nodoc:
58
+ self.class.execute(:post, *args)
59
+ end
60
+
61
+ def get(*args) #:nodoc:
62
+ self.class.execute(:get, *args)
63
+ end
64
+
65
+ def delete(*args) #:nodoc:
66
+ self.class.execute(:delete, *args)
67
+ end
68
+
69
+ def put(*args) #:nodoc:
70
+ self.class.execute(:put, *args)
71
+ end
72
+
73
+ # Do HTTP request, handle errors
74
+ def self.execute(action, path, options = {}) #:nodoc:
75
+ handle_response(Connector.send(action, path, :body => options))
76
+ end
77
+
78
+ def self.handle_response(response) #:nodoc:
79
+ case response.code
80
+ when 100..199 then
81
+ response
82
+ when 200..299 then
83
+ response
84
+ when 300.399 then
85
+ raise(response.messsage)
86
+ when 400..499 then
87
+ raise(response.message)
88
+ when 500..599 then
89
+ raise(response.message)
90
+ else
91
+ raise("Unknown Response")
92
+ end
93
+
94
+ end
95
+
96
+
97
+ # Access attributes as class methods of the Item object
98
+ def method_missing(method) #:nodoc:
99
+ return super unless attributes.has_key?(method.to_s)
100
+ attributes[method.to_s]
101
+ end
102
+ end
103
+ end
@@ -0,0 +1,11 @@
1
+ module FetchAPI
2
+ class Download < FetchAPI::Base
3
+ attr_accessor :id, :attributes
4
+
5
+ # Find :all downloads or the specified ID
6
+ def self.find(selector, params={})
7
+ super(selector, params)
8
+ end
9
+
10
+ end
11
+ end
@@ -0,0 +1,55 @@
1
+ module FetchAPI
2
+ class Item < FetchAPI::Base
3
+ attr_accessor :id, :attributes
4
+
5
+ def initialize(id_or_attributes) #:nodoc:
6
+ case id_or_attributes
7
+ when Integer, String
8
+ @attributes = get("/#{self.class.pluralized_class_name}/#{id_or_attributes.to_s}")
9
+ @attributes = @attributes[self.class.singularized_class_name]
10
+ when Hash
11
+ @attributes = id_or_attributes
12
+ end
13
+ end
14
+
15
+
16
+ #--
17
+ ################ Class Methods ###############
18
+ #--
19
+
20
+ # Find :all items or a specific SKU
21
+ def self.find(selector, params={})
22
+ super(selector, params)
23
+ end
24
+
25
+
26
+ # Creates a new Item
27
+ def self.create(options)
28
+ return FetchAPI::Item.new(execute(:post, "/items/create", :item => options)["item"])
29
+ end
30
+
31
+ #--
32
+ ################# Instance Methods ###############
33
+ #--
34
+
35
+ # Permanently deletes the Item
36
+ def destroy
37
+ delete("/items/#{sku}/delete")
38
+ end
39
+
40
+ # Immediately updates the Item
41
+ def update(options)
42
+ self.attributes = put("/items/#{sku}", :item => options)["item"]
43
+ self.id = self.sku
44
+ end
45
+
46
+ # Returns all the downloads associated with this Item
47
+ def downloads
48
+ downloads = get("/items/#{sku}/downloads")
49
+ if downloads
50
+ downloads["downloads"].map { |data| FetchAPI::Download.new(data) }
51
+ end
52
+ end
53
+
54
+ end
55
+ end
@@ -0,0 +1,84 @@
1
+ module FetchAPI
2
+
3
+ class Order < FetchAPI::Base
4
+ attr_accessor :id, :attributes
5
+
6
+ #--
7
+ ################ Class Methods ###############
8
+ #--
9
+
10
+ # Finds an Order or orders based on the specified parameters
11
+ # :all, :current, :manual, :expired, or by ID
12
+ def self.find(selector, params={})
13
+ case selector
14
+ when :current
15
+ params.merge!(:filter => "current")
16
+ orders = execute(:get, "/orders", params)
17
+ if orders["orders"].nil? || orders["orders"].empty?
18
+ return []
19
+ else
20
+ orders["orders"].map { |data| new(data) }
21
+ end
22
+ when :manual
23
+ params.merge!(:filter => "manual")
24
+ orders = execute(:get, "/orders", params)
25
+ if orders["orders"].nil? || orders["orders"].empty?
26
+ return []
27
+ else
28
+ orders["orders"].map { |data| new(data) }
29
+ end
30
+ when :expired
31
+ params.merge!(:filter => "expired")
32
+ orders = execute(:get, "/orders", params)
33
+ if orders["orders"].nil? || orders["orders"].empty?
34
+ return []
35
+ else
36
+ orders["orders"].map { |data| new(data) }
37
+ end
38
+ else
39
+ super
40
+ end
41
+ end
42
+
43
+ # Creates a new Order
44
+ def self.create(options={})
45
+ return FetchAPI::Order.new(execute(:post, "/orders/create", :order => options)["order"])
46
+ end
47
+
48
+ #--
49
+ ################# Instance Methods ###############
50
+ #--
51
+
52
+ # Permanently deletes the Order
53
+ def destroy
54
+ delete("/orders/#{id}/delete")
55
+ end
56
+
57
+ # Sets the expiration date to Time.now, stopping future downloads
58
+ def expire
59
+ post("/orders/#{id}/expire")
60
+ end
61
+
62
+ # Delivers the email containing the download instructions.
63
+ # Optional params:
64
+ # reset_expiration (true/false): Reset the order's expiration. Defaults to true.
65
+ # expiration_date (2009-04-30T15:03:46+00:00): Manually sets the order's expiration date
66
+ def send_email(options={})
67
+ post("/orders/#{id}/send_email", options)
68
+ end
69
+
70
+ # Immediately updates the Order with the new parameters
71
+ def update(options={})
72
+ self.attributes = put("/orders/#{id}", :order => options)["order"]
73
+ end
74
+
75
+ # Returns all the downloads associated with this Order
76
+ def downloads(params={})
77
+ downloads = get("/orders/#{id}/downloads")
78
+ if downloads
79
+ downloads["downloads"].map { |data| FetchAPI::Download.new(data) }
80
+ end
81
+ end
82
+
83
+ end
84
+ end
metadata ADDED
@@ -0,0 +1,106 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: fetchapp-api-ruby
3
+ version: !ruby/object:Gem::Version
4
+ hash: 23
5
+ prerelease:
6
+ segments:
7
+ - 1
8
+ - 2
9
+ - 4
10
+ version: 1.2.4
11
+ platform: ruby
12
+ authors:
13
+ - Michael Larkin
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2012-04-09 00:00:00 -04:00
19
+ default_executable:
20
+ dependencies:
21
+ - !ruby/object:Gem::Dependency
22
+ name: httparty
23
+ prerelease: false
24
+ requirement: &id001 !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ">="
28
+ - !ruby/object:Gem::Version
29
+ hash: 3
30
+ segments:
31
+ - 0
32
+ version: "0"
33
+ type: :runtime
34
+ version_requirements: *id001
35
+ description: Integrate your site with http://fetchapp.com for seamless digital delivery.
36
+ email: support@fetchapp.com
37
+ executables: []
38
+
39
+ extensions: []
40
+
41
+ extra_rdoc_files:
42
+ - CHANGELOG
43
+ - lib/fetchapp-api-ruby/account.rb
44
+ - lib/fetchapp-api-ruby/base.rb
45
+ - lib/fetchapp-api-ruby/download.rb
46
+ - lib/fetchapp-api-ruby/item.rb
47
+ - lib/fetchapp-api-ruby/order.rb
48
+ - lib/fetchapp-api-ruby.rb
49
+ - LICENSE
50
+ - README.md
51
+ files:
52
+ - CHANGELOG
53
+ - fetchapp-api-ruby.gemspec
54
+ - init.rb
55
+ - lib/fetchapp-api-ruby/account.rb
56
+ - lib/fetchapp-api-ruby/base.rb
57
+ - lib/fetchapp-api-ruby/download.rb
58
+ - lib/fetchapp-api-ruby/item.rb
59
+ - lib/fetchapp-api-ruby/order.rb
60
+ - lib/fetchapp-api-ruby.rb
61
+ - LICENSE
62
+ - Manifest
63
+ - Rakefile
64
+ - README.md
65
+ has_rdoc: true
66
+ homepage: http://github.com/getsy/fetchapp-api-ruby
67
+ licenses: []
68
+
69
+ post_install_message:
70
+ rdoc_options:
71
+ - --line-numbers
72
+ - --inline-source
73
+ - --title
74
+ - fetchapp-api-ruby
75
+ - --main
76
+ - README.md
77
+ require_paths:
78
+ - lib
79
+ required_ruby_version: !ruby/object:Gem::Requirement
80
+ none: false
81
+ requirements:
82
+ - - ">="
83
+ - !ruby/object:Gem::Version
84
+ hash: 3
85
+ segments:
86
+ - 0
87
+ version: "0"
88
+ required_rubygems_version: !ruby/object:Gem::Requirement
89
+ none: false
90
+ requirements:
91
+ - - ">="
92
+ - !ruby/object:Gem::Version
93
+ hash: 11
94
+ segments:
95
+ - 1
96
+ - 2
97
+ version: "1.2"
98
+ requirements: []
99
+
100
+ rubyforge_project:
101
+ rubygems_version: 1.5.3
102
+ signing_key:
103
+ specification_version: 2
104
+ summary: This Ruby library allows you to integrate your site with http://fetchapp.com for seamless digital delivery so you can build additional functionality while retaining the core features of Fetch. Credit for the bulk of the code goes to Thomas Reynolds.
105
+ test_files: []
106
+