dropwallet 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -16,4 +16,8 @@ Or install it yourself as:
16
16
 
17
17
  $ gem install dropwallet
18
18
 
19
- ## Usage
19
+ ## Usage
20
+
21
+ ### Gem Setup
22
+ Dropwallet::username = 'dropwallet'
23
+ Dropwallet::password = 'icuetv789'
data/Rakefile CHANGED
@@ -3,6 +3,7 @@ require "bundler/gem_tasks"
3
3
  require 'rake/testtask'
4
4
 
5
5
  Rake::TestTask.new do |t|
6
+
6
7
  t.libs << 'test'
7
8
  end
8
9
 
data/dropwallet.gemspec CHANGED
@@ -2,8 +2,8 @@
2
2
  require File.expand_path('../lib/dropwallet/version', __FILE__)
3
3
 
4
4
  Gem::Specification.new do |gem|
5
- gem.authors = ["Bill"]
6
- gem.email = ["bill@theresnobox.net"]
5
+ gem.authors = ["Bill Centinaro", "George Smith"]
6
+ gem.email = ["bill@theresnobox.net", "gsmith@icuetv.com"]
7
7
  gem.description = %q{Dropwallet API Bindings for Ruby}
8
8
  gem.summary = %q{Dropwallet API Bindings for Ruby}
9
9
  gem.homepage = "http://www.dropwallet.net"
@@ -15,9 +15,9 @@ Gem::Specification.new do |gem|
15
15
  gem.require_paths = ["lib"]
16
16
  gem.version = Dropwallet::VERSION
17
17
 
18
- #Dependencies
18
+ #Dependencies - Development
19
19
  gem.add_development_dependency "rspec"
20
-
20
+ #Dependencies - Use
21
21
  gem.add_dependency('rest-client')
22
22
  gem.add_dependency('activemodel')
23
23
  gem.add_dependency('json')
@@ -4,18 +4,22 @@ class Dropwallet::Core::Model
4
4
  include ActiveModel::Validations
5
5
 
6
6
  #attr_accessor :attributes
7
- def initialize(attributes = {})
7
+ def initialize(attributes = {}, options = {})
8
8
  @attributes = attributes
9
+ defaults = {:new => true}
10
+ options = defaults.merge(options)
11
+ @new = options[:new]
9
12
  return @attributes
10
13
  end
11
14
 
12
15
  def self.create(attributes = {}, options = {})
13
- model = self.new(attributes)
16
+ model = self.new(attributes, options)
17
+
14
18
  return model
15
19
  end
16
20
 
17
21
  def self.field(name, options = {})
18
-
22
+ name = name.to_s
19
23
  define_method("#{name}=") do |value|
20
24
  write_attribute(name, value)
21
25
  end
@@ -25,15 +29,60 @@ class Dropwallet::Core::Model
25
29
  end
26
30
 
27
31
  def read_attribute_for_validation(key)
28
- return read_attribute(key)
32
+ return read_attribute(key.to_s)
29
33
  end
30
34
 
31
35
  def read_attribute(key)
32
- @attributes[key]
36
+ @attributes[key.to_s]
33
37
  end
34
38
 
39
+
40
+
35
41
  def write_attribute(key, value)
36
- @attributes[key] = value
42
+ @attributes[key.to_s] = value
43
+ end
44
+
45
+ def self.baseServiceUrl
46
+ "https://#{Dropwallet::username}:#{Dropwallet::password}@api.dropwallet.net"
47
+ end
48
+
49
+ def self.serviceUrl
50
+ className = self.name.split('::').last.downcase
51
+ "#{baseServiceUrl}/#{className}s"
52
+ end
53
+
54
+ def self.debug?
55
+ true
37
56
  end
38
57
 
58
+
59
+
60
+ def to_s
61
+ return @attributes.to_s
62
+ end
63
+
64
+ def to_json
65
+ return @attributes.to_json
66
+ end
67
+
68
+ #Default Restful Calls
69
+ def self.find(id)
70
+ item = JSON.parse(RestClient.get("#{serviceUrl}/#{id}", {:accept => :json}))
71
+ if debug?
72
+ puts item.to_s
73
+ end
74
+ return self.new(item)
75
+ end
76
+
77
+ def self.all()
78
+ items = JSON.parse(RestClient.get("#{serviceUrl}", {:accept => :json}))
79
+ if debug?
80
+ puts item.to_s
81
+ end
82
+ objects = []
83
+ items.each do |item|
84
+ objects << self.new(item)
85
+ end
86
+ return items
87
+ end
39
88
  end
@@ -0,0 +1,10 @@
1
+ class Dropwallet::Core::Product < Dropwallet::Core::Model
2
+ field :id
3
+ field :name
4
+ field :attributes
5
+ field :description
6
+ field :brand
7
+ field :price
8
+ field :inventoryStock
9
+ field :imageUrl
10
+ end
@@ -1,5 +1,17 @@
1
1
  class Dropwallet::Core::User < Dropwallet::Core::Model
2
- validates_presence_of :email, :password
2
+ validates_presence_of :email
3
+ field :id
3
4
  field :email
4
5
  field :password
6
+ field :firstName
7
+ field :lastName
8
+
9
+ # Login Function, returns User object on success, nil on failure
10
+ def self.login(username, password)
11
+ login = JSON.parse(RestClient.post baseServiceUrl + '/session/login', "username=#{username}&password=#{password}", {:accept => :json})
12
+ if login['status'] == 'SUCCESS'
13
+ return Dropwallet::Core::User.find(login['userId'])
14
+ end
15
+ return nil
16
+ end
5
17
  end
@@ -1,5 +1,17 @@
1
1
  module Dropwallet
2
- VERSION = "0.0.1"
2
+ VERSION = "0.0.2"
3
+ def self.username
4
+ @username
5
+ end
6
+ def self.username=(name)
7
+ @username = name
8
+ end
9
+ def self.password
10
+ @password
11
+ end
12
+ def self.password=(password)
13
+ @password = password
14
+ end
3
15
  module Core
4
16
  end
5
17
  module CDN
data/lib/dropwallet.rb CHANGED
@@ -3,6 +3,7 @@ require "dropwallet/version"
3
3
  # Core Web Services
4
4
  require "dropwallet/core/model"
5
5
  require "dropwallet/core/user"
6
+ require "dropwallet/core/product"
6
7
 
7
8
  #CDN Web Services
8
9
  require "dropwallet/cdn/file"
data/test/testCdnFile.rb CHANGED
@@ -4,8 +4,7 @@ require 'dropwallet'
4
4
  class TestCdnFile < Test::Unit::TestCase
5
5
  def testUpload
6
6
  assert_nothing_raised do
7
- Dropwallet::CDN::File.upload('/Users/bcentinaro/Desktop/RealSimple_DropWalletLogo.png')
7
+ #Dropwallet::CDN::File.upload('/Users/bcentinaro/Desktop/RealSimple_DropWalletLogo.png')
8
8
  end
9
9
  end
10
-
11
10
  end
@@ -0,0 +1,20 @@
1
+ require 'test/unit'
2
+ require 'dropwallet'
3
+
4
+ class TestProduct < Test::Unit::TestCase
5
+
6
+ def testFind
7
+ RestClient.log = "stdout"
8
+ Dropwallet::username = 'dropwallet'
9
+ Dropwallet::password = 'icuetv789'
10
+ product = Dropwallet::Core::Product.find(92296)
11
+ assert_not_nil product
12
+ end
13
+ def testFind
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
@@ -3,11 +3,28 @@ require 'dropwallet'
3
3
 
4
4
  class TestUser < Test::Unit::TestCase
5
5
  def test_create
6
- user = {:email=>'test@test.com', :password=>'password'}
6
+ user = {'email'=>'test@test.com', 'password'=>'password'}
7
7
  dwUser = Dropwallet::Core::User.create(user)
8
- assert_equal user[:email], dwUser.email
9
- assert_equal user[:password], dwUser.password
8
+ assert_equal user['email'], dwUser.email
9
+ assert_equal user['password'], dwUser.password
10
10
  assert_equal dwUser.valid?, true
11
11
  assert_equal Dropwallet::Core::User.create().valid?, false
12
12
  end
13
+
14
+ def testLogin
15
+ Dropwallet::username = 'dropwallet'
16
+ Dropwallet::password = 'icuetv789'
17
+ userId = Dropwallet::Core::User.login('customer0000@icuetv.com','password')
18
+ assert_not_nil userId
19
+ end
20
+
21
+ def testFind
22
+ #RestClient.log = "stdout"
23
+ Dropwallet::username = 'dropwallet'
24
+ Dropwallet::password = 'icuetv789'
25
+ user1 = Dropwallet::Core::User.login('customer0000@icuetv.com','password')
26
+ user2 = Dropwallet::Core::User.find(user1.id)
27
+ assert_not_nil user2
28
+ assert_equal user2.id, user1.id
29
+ end
13
30
  end
metadata CHANGED
@@ -1,15 +1,16 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dropwallet
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
8
- - Bill
8
+ - Bill Centinaro
9
+ - George Smith
9
10
  autorequire:
10
11
  bindir: bin
11
12
  cert_chain: []
12
- date: 2012-08-30 00:00:00.000000000 Z
13
+ date: 2012-09-07 00:00:00.000000000 Z
13
14
  dependencies:
14
15
  - !ruby/object:Gem::Dependency
15
16
  name: rspec
@@ -78,6 +79,7 @@ dependencies:
78
79
  description: Dropwallet API Bindings for Ruby
79
80
  email:
80
81
  - bill@theresnobox.net
82
+ - gsmith@icuetv.com
81
83
  executables: []
82
84
  extensions: []
83
85
  extra_rdoc_files: []
@@ -108,6 +110,7 @@ files:
108
110
  - lib/dropwallet/.svn/text-base/version.rb.svn-base
109
111
  - lib/dropwallet/cdn/file.rb
110
112
  - lib/dropwallet/core/model.rb
113
+ - lib/dropwallet/core/product.rb
111
114
  - lib/dropwallet/core/user.rb
112
115
  - lib/dropwallet/version.rb
113
116
  - test/.svn/all-wcprops
@@ -115,6 +118,7 @@ files:
115
118
  - test/.svn/text-base/testUser.rb.svn-base
116
119
  - test/.svn/text-base/testVersion.rb.svn-base
117
120
  - test/testCdnFile.rb
121
+ - test/testProduct.rb
118
122
  - test/testUser.rb
119
123
  - test/testVersion.rb
120
124
  homepage: http://www.dropwallet.net
@@ -147,5 +151,6 @@ test_files:
147
151
  - test/.svn/text-base/testUser.rb.svn-base
148
152
  - test/.svn/text-base/testVersion.rb.svn-base
149
153
  - test/testCdnFile.rb
154
+ - test/testProduct.rb
150
155
  - test/testUser.rb
151
156
  - test/testVersion.rb