dropwallet 0.0.5 → 0.0.7

Sign up to get free protection for your applications and to get access to all the features.
@@ -46,7 +46,10 @@ class Dropwallet::Core::Model
46
46
  end
47
47
 
48
48
  def self.baseServiceUrl
49
- "https://#{Dropwallet::username}:#{Dropwallet::password}@api.dropwallet.net"
49
+ if Dropwallet::apiUrl.to_s == ''
50
+ return "https://api.dropwallet.net"
51
+ end
52
+ return Dropwallet::apiUrl.to_s
50
53
  end
51
54
 
52
55
  def self.serviceUrl
@@ -68,38 +71,55 @@ class Dropwallet::Core::Model
68
71
 
69
72
  #Default Restful Calls
70
73
  def self.find(id, options = {})
71
- defaults = {:path => "#{serviceUrl}/#{id}}"}
72
- defaults.merge(options)
73
- item = JSON.parse(RestClient.get(defaults[:path], {:accept => :json}))
74
- if debug?
75
- puts item.to_s
74
+ if options[:path].nil?
75
+ options[:path] = serviceUrl
76
+ end
77
+ options[:path] = (options[:path] << "/#{id}")
78
+ doc = JSON.parse(RestClient.get(options[:path], {:accept => :json}))
79
+ if doc.include? 'errorMessage'
80
+ raise doc['errorMessage']
76
81
  end
77
- if item.include? 'errorMessage'
78
- raise item['errorMessage']
79
- end
80
- return self.new(item, :new=>false)
82
+ return self.new(doc, :new=>false)
81
83
  end
82
84
 
83
- def self.all(page = 0, options={})
85
+ def self.all(page=1, options={})
84
86
  defaults = {:path => "#{serviceUrl}"}
85
- defaults.merge(options)
86
- items = JSON.parse(RestClient.get(defaults[:path], {:accept => :json}))
87
- if items.include? 'errorMessage'
88
- raise items['errorMessage']
89
- end
90
- if debug?
91
- puts items.to_s
87
+ options.merge(defaults)
88
+ options[:path] = (options[:path] << "?page=#{page}&limit=20")
89
+ doc = JSON.parse(RestClient.get(options[:path], {:accept => :json}))
90
+ if doc.include? 'errorMessage'
91
+ raise doc['errorMessage']
92
92
  end
93
93
  objects = []
94
- items.each do |item|
94
+ doc['items'].each do |item|
95
95
  objects << self.new(item)
96
96
  end
97
- return items
97
+ return objects
98
98
  end
99
99
 
100
100
 
101
- def self.count
102
- return 0
101
+ def self.count(options={})
102
+ defaults = {:path => "#{serviceUrl}"}
103
+ options.merge(defaults)
104
+ options[:path] = (options[:path] << "?page=1&limit=1")
105
+ puts options[:path]
106
+ doc = JSON.parse(RestClient.get(options[:path], {:accept => :json}))
107
+ if doc.include? 'errorMessage'
108
+ raise doc['errorMessage']
109
+ end
110
+ return doc['pages']
111
+ end
112
+
113
+ def self.pages(options={})
114
+ defaults = {:path => "#{serviceUrl}"}
115
+ options.merge(defaults)
116
+ options[:path] = (options[:path] << "?page=1&limit=20")
117
+ puts options[:path]
118
+ doc = JSON.parse(RestClient.get(options[:path], {:accept => :json}))
119
+ if doc.include? 'errorMessage'
120
+ raise doc['errorMessage']
121
+ end
122
+ return doc['pages']
103
123
  end
104
124
 
105
125
  def save(options = {})
@@ -108,7 +128,7 @@ class Dropwallet::Core::Model
108
128
  end
109
129
  defaults = {:path => "#{serviceUrl}"}
110
130
  defaults.merge(options)
111
- item = JSON.parse(RestClient.post(defaults[:path], to_json, {:accept => :json}))
131
+ item = JSON.parse(RestClient.post(defaults[:path].strip, to_json, {:accept => :json}))
112
132
  if item.include? 'errorMessage'
113
133
  raise item['errorMessage']
114
134
  end
@@ -122,13 +142,13 @@ class Dropwallet::Core::Model
122
142
  end
123
143
  defaults = {:path => "#{serviceUrl}/#{id}"}
124
144
  defaults.merge(options)
125
- return JSON.parse(RestClient.put(defaults[:path], to_json, {:accept => :json}))
145
+ return JSON.parse(RestClient.put(defaults[:path].strip, to_json, {:accept => :json}))
126
146
  end
127
147
 
128
148
  def delete(options={})
129
149
  defaults = {:path => "#{serviceUrl}/#{id}"}
130
150
  defaults.merge(options)
131
- item = JSON.parse(RestClient.delete(defaults[:path], {:accept => :json}))
151
+ item = JSON.parse(RestClient.delete(defaults[:path].strip, {:accept => :json}))
132
152
  if item.include? 'errorMessage'
133
153
  raise item['errorMessage']
134
154
  end
@@ -139,7 +159,7 @@ class Dropwallet::Core::Model
139
159
  def self.delete(itemId, options={})
140
160
  defaults = {:path => "#{serviceUrl}/#{itemId}"}
141
161
  defaults.merge(options)
142
- item = JSON.parse(RestClient.delete(defaults[:path], {:accept => :json}))
162
+ item = JSON.parse(RestClient.delete(defaults[:path].strip, {:accept => :json}))
143
163
  if item.include? 'errorMessage'
144
164
  raise item['errorMessage']
145
165
  end
@@ -1,9 +1,25 @@
1
1
  class Dropwallet::Core::Order < Dropwallet::Core::Model
2
- field :id
3
- field :grandtotal
4
- field :total
5
- field :productName
6
- field :status
7
- field :productSku
8
- field :qty
2
+ field :orderId
3
+ field :orderDate
4
+ field :grandTotal
5
+ field :taxTotal
6
+ field :shippingTotal
7
+ field :subTotal
8
+ field :shippingAddress
9
+ field :items
10
+
11
+ def status
12
+ canceled = true
13
+ self.items.each do |item|
14
+ if item['status'].upcase != 'CANCELLED'
15
+ canceled= false
16
+ end
17
+ end
18
+
19
+ if canceled
20
+ return 'CANCELLED'
21
+ end
22
+
23
+ return ''
24
+ end
9
25
  end
@@ -6,6 +6,20 @@ class Dropwallet::Core::User < Dropwallet::Core::Model
6
6
  field :firstName
7
7
  field :lastName
8
8
 
9
+ def orders(page = 1)
10
+ options = {:path => "#{Dropwallet::Core::Model.baseServiceUrl}/users/#{id}/orders.json"}
11
+ return Dropwallet::Core::Order.all(page, options)
12
+ end
13
+
14
+ def order(orderId)
15
+ options = {:path => "#{Dropwallet::Core::Model.baseServiceUrl}/users/#{id}/orders"}
16
+ return Dropwallet::Core::Order.find(orderId, options)
17
+ end
18
+
19
+ def ordersPages
20
+ options = {:path => "#{Dropwallet::Core::Model.baseServiceUrl}/users/#{id}/orders.json"}
21
+ return Dropwallet::Core::Order.pages(options)
22
+ end
9
23
  # Login Function, returns User object on success, nil on failure
10
24
  def self.login(username, password)
11
25
  login = JSON.parse(RestClient.post baseServiceUrl + '/session/login', "username=#{username}&password=#{password}", {:accept => :json})
@@ -1,5 +1,5 @@
1
1
  module Dropwallet
2
- VERSION = "0.0.5"
2
+ VERSION = "0.0.7"
3
3
 
4
4
  def self.username
5
5
  @username
@@ -7,7 +7,7 @@ module Dropwallet
7
7
  def self.username=(name)
8
8
  @username = name
9
9
  end
10
- def self.password
10
+ def self.password
11
11
  @password
12
12
  end
13
13
  def self.password=(password)
@@ -19,6 +19,12 @@ module Dropwallet
19
19
  def self.cache
20
20
  return @cache
21
21
  end
22
+ def self.apiUrl
23
+ @apiUrl
24
+ end
25
+ def self.apiUrl=(apiUrl)
26
+ @apiUrl = apiUrl
27
+ end
22
28
 
23
29
  module Core
24
30
  end
data/lib/dropwallet.rb CHANGED
@@ -4,6 +4,7 @@ require "dropwallet/version"
4
4
  require "dropwallet/core/model"
5
5
  require "dropwallet/core/user"
6
6
  require "dropwallet/core/product"
7
+ require "dropwallet/core/order"
7
8
 
8
9
  #CDN Web Services
9
10
  require "dropwallet/cdn/file"
data/test/testCdnFile.rb CHANGED
@@ -1,10 +1,10 @@
1
- require 'test/unit'
2
- require 'dropwallet'
1
+ # require 'test/unit'
2
+ # require 'dropwallet'
3
3
 
4
- class TestCdnFile < Test::Unit::TestCase
5
- def testUpload
6
- assert_nothing_raised do
7
- Dropwallet::CDN::File.upload('/Users/bcentinaro/Desktop/RealSimple_DropWalletLogo.png' ,'Test', 'folder/secondFolder/logo.png')
8
- end
9
- end
10
- end
4
+ # class TestCdnFile < Test::Unit::TestCase
5
+ # def testUpload
6
+ # assert_nothing_raised do
7
+ # #Dropwallet::CDN::File.upload('/Users/bcentinaro/Desktop/RealSimple_DropWalletLogo.png' ,'Test', 'folder/secondFolder/logo.png')
8
+ # end
9
+ # end
10
+ # end
@@ -0,0 +1,17 @@
1
+ require 'test/unit'
2
+ require 'dropwallet'
3
+
4
+ class TestOrders < Test::Unit::TestCase
5
+ def testOrders
6
+ RestClient.log = "/dev/null"
7
+ Dropwallet::username = 'dropwallet'
8
+ Dropwallet::password = 'icuetv789'
9
+ user1 = Dropwallet::Core::User.login('customer0000@icuetv.com','password')
10
+ items = user1.orders
11
+ puts 'ORDERS'
12
+ items.each do |item|
13
+ #order = Dropwallet::Core::Order.find(item.orderId)
14
+ end
15
+
16
+ end
17
+ end
data/test/testProduct.rb CHANGED
@@ -1,20 +1,20 @@
1
- require 'test/unit'
2
- require 'dropwallet'
1
+ # require 'test/unit'
2
+ # require 'dropwallet'
3
3
 
4
- class TestProduct < Test::Unit::TestCase
4
+ # class TestProduct < Test::Unit::TestCase
5
5
 
6
- def testFind
7
- RestClient.log = "stdout"
8
- Dropwallet::username = 'dropwallet'
9
- Dropwallet::password = 'icuetv789'
10
- product = Dropwallet::Core::Product.find(123)
11
- assert_not_nil product
12
- end
13
- def testAll
14
- RestClient.log = "stdout"
15
- Dropwallet::username = 'dropwallet'
16
- Dropwallet::password = 'icuetv789'
17
- products = Dropwallet::Core::Product.all
18
- assert_not_nil products
19
- end
20
- end
6
+ # def testFind
7
+ # RestClient.log = "stdout"
8
+ # Dropwallet::username = 'dropwallet'
9
+ # Dropwallet::password = 'icuetv789'
10
+ # product = Dropwallet::Core::Product.find(123)
11
+ # assert_not_nil product
12
+ # end
13
+ # def testAll
14
+ # RestClient.log = "stdout"
15
+ # Dropwallet::username = 'dropwallet'
16
+ # Dropwallet::password = 'icuetv789'
17
+ # products = Dropwallet::Core::Product.all
18
+ # assert_not_nil products
19
+ # end
20
+ # end
data/test/testUser.rb CHANGED
@@ -27,4 +27,17 @@ class TestUser < Test::Unit::TestCase
27
27
  assert_not_nil user2
28
28
  assert_equal user2.id, user1.id
29
29
  end
30
+ def testOrders
31
+ RestClient.log = "/dev/null"
32
+ Dropwallet::username = 'dropwallet'
33
+ Dropwallet::password = 'icuetv789'
34
+ user1 = Dropwallet::Core::User.login('customer0000@icuetv.com','password')
35
+ items = user1.orders
36
+ puts 'ORDERS'
37
+ items.each do |item|
38
+ order = user1.order(item.orderId)
39
+ puts order.to_s
40
+ end
41
+ puts "Pages: #{user1.ordersPages}"
42
+ end
30
43
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dropwallet
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.5
4
+ version: 0.0.7
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2012-09-17 00:00:00.000000000 Z
13
+ date: 2012-09-24 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: rspec
@@ -102,6 +102,7 @@ files:
102
102
  - lib/dropwallet/core/user.rb
103
103
  - lib/dropwallet/version.rb
104
104
  - test/testCdnFile.rb
105
+ - test/testOrders.rb
105
106
  - test/testProduct.rb
106
107
  - test/testUser.rb
107
108
  - test/testVersion.rb
@@ -131,6 +132,7 @@ specification_version: 3
131
132
  summary: Dropwallet API Bindings for Ruby
132
133
  test_files:
133
134
  - test/testCdnFile.rb
135
+ - test/testOrders.rb
134
136
  - test/testProduct.rb
135
137
  - test/testUser.rb
136
138
  - test/testVersion.rb