pixallent-fetchapi-ruby 0.9.1 → 0.9.2
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.
- data/CHANGELOG +4 -0
- data/README +6 -2
- data/Rakefile +1 -1
- data/fetchapi-ruby.gemspec +2 -2
- data/lib/fetchapi/account.rb +5 -3
- data/lib/fetchapi/base.rb +30 -15
- data/lib/fetchapi/download.rb +6 -0
- data/lib/fetchapi/item.rb +21 -9
- data/lib/fetchapi/order.rb +8 -5
- metadata +2 -2
data/CHANGELOG
CHANGED
data/README
CHANGED
@@ -1,13 +1,17 @@
|
|
1
|
-
|
1
|
+
= Installation
|
2
|
+
From Github
|
2
3
|
gem sources -a http://gems.github.com (you only have to do this once)
|
3
4
|
gem install pixallent-fetchapi-ruby
|
5
|
+
|
6
|
+
RubyForge
|
7
|
+
coming soon!
|
4
8
|
|
5
9
|
= Setup
|
6
10
|
FetchAPI::Base.basic_auth('youraccount.fetchapp.com', 'demokey', 'demotoken')
|
7
11
|
|
8
12
|
= Account
|
9
13
|
|
10
|
-
FetchAPI::Account.details
|
14
|
+
account = FetchAPI::Account.details
|
11
15
|
|
12
16
|
token = FetchAPI::Account.new_token *Subsequent calls will use the new token automatically
|
13
17
|
|
data/Rakefile
CHANGED
@@ -2,7 +2,7 @@ require 'rubygems'
|
|
2
2
|
require 'rake'
|
3
3
|
require 'echoe'
|
4
4
|
|
5
|
-
Echoe.new('fetchapi-ruby', '0.9.
|
5
|
+
Echoe.new('fetchapi-ruby', '0.9.2') do |p|
|
6
6
|
p.description = "Integrate your site with http://fetchapp.com for seamless digital delivery."
|
7
7
|
p.url = "http://github.com/pixallent/fetchapi-ruby"
|
8
8
|
p.author = ["Thomas Reynolds, Michael Larkin"]
|
data/fetchapi-ruby.gemspec
CHANGED
@@ -2,11 +2,11 @@
|
|
2
2
|
|
3
3
|
Gem::Specification.new do |s|
|
4
4
|
s.name = %q{fetchapi-ruby}
|
5
|
-
s.version = "0.9.
|
5
|
+
s.version = "0.9.2"
|
6
6
|
|
7
7
|
s.required_rubygems_version = Gem::Requirement.new(">= 1.2") if s.respond_to? :required_rubygems_version=
|
8
8
|
s.authors = ["Thomas Reynolds, Michael Larkin"]
|
9
|
-
s.date = %q{2009-05-
|
9
|
+
s.date = %q{2009-05-04}
|
10
10
|
s.description = %q{Integrate your site with http://fetchapp.com for seamless digital delivery.}
|
11
11
|
s.email = %q{mikelarkin@pixallent.com}
|
12
12
|
s.extra_rdoc_files = ["CHANGELOG", "lib/fetchapi/account.rb", "lib/fetchapi/base.rb", "lib/fetchapi/download.rb", "lib/fetchapi/item.rb", "lib/fetchapi/order.rb", "lib/fetchapi-ruby.rb", "LICENSE", "README"]
|
data/lib/fetchapi/account.rb
CHANGED
@@ -1,12 +1,15 @@
|
|
1
1
|
module FetchAPI
|
2
2
|
class Account < FetchAPI::Base
|
3
|
+
attr_accessor :attributes
|
3
4
|
#--
|
4
5
|
################ Class Methods ###############
|
5
6
|
#--
|
6
7
|
|
7
8
|
# Retrieves information about the Account
|
8
9
|
def self.details
|
9
|
-
|
10
|
+
account = Account.new({})
|
11
|
+
account.attributes = execute(:get, "/account")["account"]
|
12
|
+
account
|
10
13
|
end
|
11
14
|
|
12
15
|
# Generates a new API token. Subsequent API calls using the
|
@@ -15,8 +18,7 @@ module FetchAPI
|
|
15
18
|
token = execute(:get, "/new_token")
|
16
19
|
unless token["message"].blank?
|
17
20
|
# Reauthorize
|
18
|
-
|
19
|
-
Connector.basic_auth(@key, token["message"])
|
21
|
+
Connector.basic_auth(FetchAPI::Base.key, token["message"])
|
20
22
|
token
|
21
23
|
end
|
22
24
|
end
|
data/lib/fetchapi/base.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
module FetchAPI
|
2
2
|
class Base
|
3
|
-
|
4
|
-
def initialize(id_or_attributes)
|
3
|
+
require 'pp'
|
4
|
+
def initialize(id_or_attributes) #:nodoc:
|
5
5
|
case id_or_attributes
|
6
6
|
when Integer, String
|
7
7
|
@attributes = get("/#{self.class.pluralized_class_name}/#{id_or_attributes.to_s}")
|
@@ -13,7 +13,7 @@ module FetchAPI
|
|
13
13
|
end
|
14
14
|
end
|
15
15
|
|
16
|
-
def self.find(selector, params={})
|
16
|
+
def self.find(selector, params={}) #:nodoc:
|
17
17
|
case selector
|
18
18
|
when :all
|
19
19
|
objects = execute(:get, "/#{pluralized_class_name}")
|
@@ -28,38 +28,53 @@ module FetchAPI
|
|
28
28
|
end
|
29
29
|
end
|
30
30
|
|
31
|
-
class Connector
|
31
|
+
class Connector #:nodoc:
|
32
32
|
include HTTParty
|
33
33
|
format :xml
|
34
34
|
end
|
35
35
|
|
36
|
-
# Initializes the connection
|
36
|
+
# Initializes the connection to the API
|
37
37
|
def self.basic_auth(url, key, token)
|
38
|
-
|
38
|
+
@key = key # Save this in case they generate a new token later
|
39
39
|
Connector.base_uri(url)
|
40
40
|
Connector.basic_auth(key, token)
|
41
41
|
end
|
42
42
|
|
43
|
+
def self.key #:nodoc:
|
44
|
+
return @key
|
45
|
+
end
|
46
|
+
|
43
47
|
protected
|
44
|
-
def self.singularized_class_name
|
48
|
+
def self.singularized_class_name #:nodoc:
|
45
49
|
ancestors.first.to_s.split('::').last.downcase
|
46
50
|
end
|
47
|
-
def self.pluralized_class_name
|
51
|
+
def self.pluralized_class_name #:nodoc:
|
48
52
|
ancestors.first.to_s.split('::').last.downcase << 's'
|
49
53
|
end
|
50
54
|
|
51
|
-
def post(*args)
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
+
def post(*args) #:nodoc:
|
56
|
+
self.class.execute(:post, *args)
|
57
|
+
end
|
58
|
+
|
59
|
+
def get(*args) #:nodoc:
|
60
|
+
self.class.execute(:get, *args)
|
61
|
+
end
|
62
|
+
|
63
|
+
def delete(*args) #:nodoc:
|
64
|
+
self.class.execute(:delete, *args)
|
65
|
+
end
|
66
|
+
|
67
|
+
def put(*args) #:nodoc:
|
68
|
+
self.class.execute(:put, *args)
|
69
|
+
end
|
55
70
|
|
56
71
|
# Do HTTP request, handle errors
|
57
|
-
def self.execute(action, path, options = {})
|
72
|
+
def self.execute(action, path, options = {}) #:nodoc:
|
58
73
|
handle_response(Connector.send(action, path, :query => options))
|
59
74
|
#Connector.send(action, path, options)
|
60
75
|
end
|
61
76
|
|
62
|
-
def self.handle_response(response)
|
77
|
+
def self.handle_response(response) #:nodoc:
|
63
78
|
case response.code
|
64
79
|
when 100..199 then response
|
65
80
|
when 200..299 then response
|
@@ -77,7 +92,7 @@ module FetchAPI
|
|
77
92
|
|
78
93
|
|
79
94
|
# Access attributes as class methods of the Item object
|
80
|
-
def method_missing(method)
|
95
|
+
def method_missing(method) #:nodoc:
|
81
96
|
return super unless attributes.has_key?(method.to_s)
|
82
97
|
attributes[method.to_s]
|
83
98
|
end
|
data/lib/fetchapi/download.rb
CHANGED
data/lib/fetchapi/item.rb
CHANGED
@@ -1,8 +1,8 @@
|
|
1
1
|
module FetchAPI
|
2
2
|
class Item < FetchAPI::Base
|
3
|
-
|
3
|
+
attr_accessor :id, :attributes
|
4
4
|
|
5
|
-
def initialize(id_or_attributes)
|
5
|
+
def initialize(id_or_attributes) #:nodoc:
|
6
6
|
case id_or_attributes
|
7
7
|
when Integer, String
|
8
8
|
@attributes = get("/#{self.class.pluralized_class_name}/#{id_or_attributes.to_s}")
|
@@ -12,9 +12,18 @@ module FetchAPI
|
|
12
12
|
end
|
13
13
|
end
|
14
14
|
|
15
|
+
|
15
16
|
#--
|
16
17
|
################ Class Methods ###############
|
17
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
|
18
27
|
def self.create(options)
|
19
28
|
return FetchAPI::Item.new(execute(:post, "/items/create", :item => options)["item"])
|
20
29
|
end
|
@@ -23,21 +32,24 @@ module FetchAPI
|
|
23
32
|
################# Instance Methods ###############
|
24
33
|
#--
|
25
34
|
|
35
|
+
# Permanently deletes the Item
|
26
36
|
def destroy
|
27
37
|
delete("/items/#{sku}/delete")
|
28
38
|
end
|
29
39
|
|
40
|
+
# Immediately updates the Item
|
30
41
|
def update(options)
|
31
42
|
self.attributes = put("/items/#{sku}", :item => options)["item"]
|
32
|
-
|
43
|
+
self.id = self.sku
|
33
44
|
end
|
34
45
|
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
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
|
41
53
|
|
42
54
|
|
43
55
|
end
|
data/lib/fetchapi/order.rb
CHANGED
@@ -6,7 +6,9 @@ module FetchAPI
|
|
6
6
|
#--
|
7
7
|
################ Class Methods ###############
|
8
8
|
#--
|
9
|
-
|
9
|
+
|
10
|
+
# Finds an Order or orders based on the specified parameters
|
11
|
+
# :all, :current, :manual, :expired, or by ID
|
10
12
|
def self.find(selector, params={})
|
11
13
|
case selector
|
12
14
|
when :current
|
@@ -38,7 +40,7 @@ module FetchAPI
|
|
38
40
|
end
|
39
41
|
end
|
40
42
|
|
41
|
-
# Creates a new
|
43
|
+
# Creates a new Order
|
42
44
|
def self.create(options={})
|
43
45
|
return FetchAPI::Order.new(execute(:post, "/orders/create", :order => options)["order"])
|
44
46
|
end
|
@@ -47,7 +49,7 @@ module FetchAPI
|
|
47
49
|
################# Instance Methods ###############
|
48
50
|
#--
|
49
51
|
|
50
|
-
# Permanently deletes the
|
52
|
+
# Permanently deletes the Order
|
51
53
|
def destroy
|
52
54
|
delete("/orders/#{id}/delete")
|
53
55
|
end
|
@@ -65,11 +67,12 @@ module FetchAPI
|
|
65
67
|
post("/orders/#{id}/send_email", options)
|
66
68
|
end
|
67
69
|
|
68
|
-
# Immediately updates the
|
70
|
+
# Immediately updates the Order with the new parameters
|
69
71
|
def update(options={})
|
70
72
|
self.attributes = put("/orders/#{id}", :order => options)["order"]
|
71
73
|
end
|
72
|
-
|
74
|
+
|
75
|
+
# Returns all the downloads associated with this Order
|
73
76
|
def downloads(params={})
|
74
77
|
downloads = get("/orders/#{id}/downloads")
|
75
78
|
if downloads
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: pixallent-fetchapi-ruby
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.9.
|
4
|
+
version: 0.9.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Thomas Reynolds, Michael Larkin
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2009-05-
|
12
|
+
date: 2009-05-04 00:00:00 -07:00
|
13
13
|
default_executable:
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|