vworkapp_ruby 0.0.1 → 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.
data/.gitignore ADDED
@@ -0,0 +1,3 @@
1
+ .DS_Store
2
+ .bundle
3
+ .gem
data/Gemfile.lock ADDED
@@ -0,0 +1,38 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ vworkapp_ruby (0.0.1)
5
+ gcoder
6
+ httparty
7
+
8
+ GEM
9
+ remote: http://rubygems.org/
10
+ specs:
11
+ diff-lcs (1.1.3)
12
+ gcoder (0.12.1)
13
+ hashie
14
+ ruby-hmac
15
+ yajl-ruby
16
+ hashie (1.2.0)
17
+ httparty (0.8.1)
18
+ multi_json
19
+ multi_xml
20
+ multi_json (1.0.4)
21
+ multi_xml (0.4.1)
22
+ rspec (2.7.0)
23
+ rspec-core (~> 2.7.0)
24
+ rspec-expectations (~> 2.7.0)
25
+ rspec-mocks (~> 2.7.0)
26
+ rspec-core (2.7.1)
27
+ rspec-expectations (2.7.0)
28
+ diff-lcs (~> 1.1.2)
29
+ rspec-mocks (2.7.0)
30
+ ruby-hmac (0.4.0)
31
+ yajl-ruby (1.1.0)
32
+
33
+ PLATFORMS
34
+ ruby
35
+
36
+ DEPENDENCIES
37
+ rspec
38
+ vworkapp_ruby!
data/README.md CHANGED
@@ -11,5 +11,8 @@ This is a wrapper around vWorkApp's API. Go on! Use it!
11
11
 
12
12
  - Broken API bits:
13
13
  * What's find(:search) for??.
14
- * customer_name broken?
15
- * Why can't I filter by template?
14
+ * Why can't I filter by template?
15
+
16
+ - Missing job.actual_duration, job.actual_start_at
17
+
18
+ - Should have connivence method to lookup a customer from a job
@@ -31,4 +31,4 @@ job = VWorkApp::Job.new(
31
31
  VWorkApp::CustomField.new("Note", "Hi There!"),
32
32
  ]
33
33
  )
34
- p job.create
34
+ puts "Created Job, id is: #{job.create.id}"
@@ -21,14 +21,11 @@ EOL
21
21
  workers = VWorkApp::Worker.all
22
22
 
23
23
  workers.each do |worker|
24
- puts "Worker: #{worker.name}"
24
+ puts "Worker: #{worker.id}-#{worker.name}"
25
25
  jobs = VWorkApp::Job.find(:worker_id => worker.id, :state => "not_started")
26
26
  jobs.each do |job|
27
27
  puts "\t #{job.third_party_id || job.id}, #{job.customer_name}, #{job.template_name}"
28
+ # p job
28
29
  end
29
30
  puts ""
30
31
  end
31
-
32
- # p jobs = VWorkApp::Job.find(:worker_id => 4228)["cars"]
33
-
34
- # p job = VWorkApp::Job.show(180022)
data/lib/vworkapp_ruby.rb CHANGED
@@ -1,4 +1,5 @@
1
1
  require 'vworkapp_ruby/base'
2
+ require 'vworkapp_ruby/location'
2
3
  require 'vworkapp_ruby/job'
3
4
  require 'vworkapp_ruby/worker'
4
5
  require 'vworkapp_ruby/customer'
@@ -6,3 +7,5 @@ require 'vworkapp_ruby/response_error'
6
7
  # require 'vworkapp/proof_of_delivery'
7
8
 
8
9
  require 'vworkapp_ruby/httparty_monkey_patch'
10
+
11
+ VW = VWorkApp
@@ -1,4 +1,5 @@
1
1
  require 'httparty'
2
+ require 'active_support/core_ext/hash'
2
3
 
3
4
  module VWorkApp
4
5
 
@@ -8,33 +9,64 @@ module VWorkApp
8
9
  def api_key=(key)
9
10
  @api_key = key
10
11
  end
12
+
11
13
  def api_key
12
14
  @api_key
13
15
  end
16
+
14
17
  end
15
18
 
16
- class Base
19
+ module AttributeEquality
20
+ def attributes_eql?(other, attributes)
21
+ attributes.each do |attribute|
22
+ return false unless self.send(attribute.to_sym) == other.send(attribute.to_sym)
23
+ end
24
+ true
25
+ end
26
+ end
17
27
 
28
+ class Base
18
29
  include HTTParty
30
+ include AttributeEquality
19
31
 
20
32
  base_uri 'api.vworkapp.com/api/2.0'
21
33
  # http_proxy 'localhost', 8888
22
- # format :xml
23
34
 
24
35
  headers({
36
+ "Content-Type" => "text/xml",
25
37
  "User-Agent" => "Ruby.vWorkApp.API"
26
38
  })
27
39
 
28
- # Examines a bad response and raises an approriate exception
29
- #
30
- # @param [HTTParty::Response] response
31
- def self.bad_response(response)
32
- if response.class == HTTParty::Response
33
- raise ResponseError, response
40
+ def self.perform(action, url, query = {}, body = nil)
41
+ options = {}
42
+ options[:query] = { :api_key => VWorkApp.api_key }.merge(query)
43
+
44
+ if body
45
+ root = body.keys.first
46
+ body_str = body[root].to_xml(:root => root)
47
+ options[:body] = body_str
48
+ end
49
+
50
+ raw = self.send(action, url, options)
51
+
52
+ case raw.response
53
+ when Net::HTTPOK, Net::HTTPCreated
54
+ yield(raw) if block_given?
55
+ when Net::HTTPNotFound
56
+ nil
57
+ else
58
+ bad_response(raw.response)
34
59
  end
35
- raise StandardError, "Unkown error"
60
+ end
61
+
62
+ def perform(action, url, query = {}, body = nil, &block)
63
+ self.class.perform(action, url, query, body, &block)
36
64
  end
37
65
 
66
+ def self.bad_response(response)
67
+ raise "#{response.code} - #{response.msg}: #{response.body}"
68
+ end
69
+
38
70
  end
39
71
 
40
72
  end
@@ -0,0 +1,106 @@
1
+ module VWorkApp
2
+
3
+ class Customer < Base
4
+ attr_accessor :id, :third_party_id, :name, :site_contact, :billing_contact
5
+
6
+ #---------------
7
+ # Object Methods
8
+ #---------------
9
+
10
+ def initialize(name, id = nil, third_party_id = nil, site_contact = nil, billing_contact = nil)
11
+ @name = name
12
+ @id = id
13
+ @third_party_id = third_party_id
14
+ @site_contact = site_contact
15
+ @billing_contact = billing_contact
16
+ end
17
+
18
+ def self.from_hash(attributes)
19
+ customer = Customer.new(attributes["name"], attributes["id"], attributes["third_party_id"])
20
+ customer.site_contact = Contact.from_hash(attributes["delivery_contact"])
21
+ customer.billing_contact = Contact.from_hash(attributes["billing_contact"])
22
+ customer
23
+ end
24
+
25
+ def to_hash
26
+ cust_hash = { :customer => { :name => self.name } }
27
+ cust_hash[:customer][:third_party_id] = self.third_party_id if third_party_id
28
+ cust_hash[:customer][:delivery_contact] = self.site_contact.to_hash if site_contact
29
+ cust_hash[:customer][:billing_contact] = self.billing_contact.to_hash if billing_contact
30
+ cust_hash
31
+ end
32
+
33
+ def ==(other)
34
+ attributes_eql?(other, [:id, :name, :third_party_id, :site_contact, :billing_contact])
35
+ end
36
+
37
+ #---------------
38
+ # REST Methods
39
+ #---------------
40
+
41
+ def create
42
+ perform(:post, "/customers.xml", {}, self.to_hash) do |res|
43
+ Customer.from_hash(res["customer"])
44
+ end
45
+ end
46
+
47
+ def update(use_third_party_id = false)
48
+ perform(:put, "/customers/#{id}.xml", { :use_third_party_id => use_third_party_id }, self.to_hash)
49
+ end
50
+
51
+ def delete(use_third_party_id = false)
52
+ perform(:delete, "/customers/#{id}.xml", { :use_third_party_id => use_third_party_id })
53
+ end
54
+
55
+ def self.show(id, use_third_party_id = false)
56
+ perform(:get, "/customers/#{id}.xml", :use_third_party_id => use_third_party_id) do |res|
57
+ Customer.from_hash(res["customer"])
58
+ end
59
+ end
60
+
61
+ def self.find
62
+ self.perform(:get, "/customers.xml") do |res|
63
+ res["customers"].map { |h| Customer.from_hash(h) }
64
+ end
65
+ end
66
+
67
+ end
68
+
69
+ class Contact < Base
70
+ include AttributeEquality
71
+ attr_accessor :first_name, :last_name, :phone, :mobile, :email, :location
72
+
73
+ def initialize(first_name = nil, last_name = nil, phone = nil, mobile = nil, email = nil, location = nil)
74
+ @first_name = first_name
75
+ @last_name = last_name
76
+ @phone = phone
77
+ @mobile = mobile
78
+ @email = email
79
+ @location = location
80
+ end
81
+
82
+ def self.from_hash(attributes)
83
+ contact = Contact.new(attributes["first_name"], attributes["last_name"], attributes["phone"], attributes["mobile"], attributes["email"])
84
+ contact.location = Location.from_hash(attributes["location"])
85
+ contact
86
+ end
87
+
88
+ def to_hash
89
+ contact_hash = {
90
+ :first_name => self.first_name,
91
+ :last_name => self.last_name,
92
+ :phone => self.phone,
93
+ :mobile => self.mobile,
94
+ :email => self.email
95
+ }
96
+ contact_hash[:location] = self.location.to_hash if location
97
+ contact_hash
98
+ end
99
+
100
+ def ==(other)
101
+ attributes_eql?(other, [:first_name, :last_name, :phone, :mobile, :email, :location])
102
+ end
103
+
104
+ end
105
+
106
+ end
@@ -2,98 +2,26 @@ require 'gcoder'
2
2
 
3
3
  module VWorkApp
4
4
 
5
- class Location
6
- attr_accessor :formatted_address, :lat, :lng
7
- def initialize(formatted_address, lat, lng)
8
- @formatted_address = formatted_address
9
- @lat = lat
10
- @lng = lng
11
- end
12
-
13
- def self.from_address(address, region = :us)
14
- loc = Location.geocode(address, region).first.geometry.location
15
- self.new(address, loc.lat, loc.lng)
16
- end
17
-
18
- def to_hash
19
- { :formatted_address => formatted_address, :lat => lat, :lng => lng }
20
- end
21
-
22
- def self.from_hash(attributes)
23
- return nil unless attributes
24
- Location.new(attributes["formatted_address"], attributes["lat"], attributes["lng"])
25
- end
26
-
27
- private
28
-
29
- def self.geocode(address, region)
30
- @gecoder ||= GCoder.connect(:storage => :heap)
31
- @gecoder[address, { :region => region }]
32
- end
33
-
34
- end
35
-
36
- class Step
37
- attr_accessor :name, :location
38
- def initialize(name, location = nil)
39
- @name = name
40
- @location = location
41
- end
42
-
43
- def to_hash
44
- h = { :name => name }
45
- h.merge!({ :location => location.to_hash }) if location
46
- h
47
- end
48
-
49
- def self.from_hash(attributes)
50
- Step.new(attributes["name"], Location.from_hash(attributes["location"]))
51
- end
52
-
53
- end
5
+ class Job < Base
6
+ attr_accessor :id, :customer_name, :template_name, :planned_duration, :steps, :custom_fields, :third_party_id
7
+ attr_accessor :assigned_to_id, :planned_start_at, :progress_state
54
8
 
55
- class CustomField
56
- attr_accessor :name, :value
57
- def initialize(name, value)
58
- @name = name
59
- @value = value
60
- end
9
+ #---------------
10
+ # Object Methods
11
+ #---------------
61
12
 
62
- def to_hash
63
- { :name => name.to_s, :value => value.to_s }
64
- end
65
-
66
- def self.from_hash(attributes)
67
- CustomField.new(attributes["name"], attributes["value"])
68
- end
69
-
70
- end
71
-
72
- class Job < Base
73
-
74
- attr_accessor :id, :customer_name, :template_name, :planned_duration, :steps, :custom_fields, :third_party_id, :assigned_to, :planned_start_at
75
-
76
- ##
77
- # Creates a new jobs in vWorkApp.
78
- #
79
- # Steps and Custom_Fields takes an array of these.
80
- #
81
- def initialize(customer_name, template_name, planned_duration, steps, custom_fields = nil, id = nil, third_party_id = nil, assigned_to = nil, planned_start_at = nil)
13
+ def initialize(customer_name, template_name, planned_duration, steps, custom_fields = nil, id = nil, third_party_id = nil, assigned_to_id = nil, planned_start_at = nil)
82
14
  @id = id
83
15
  @customer_name = customer_name
84
- @template_name = template_name
16
+ @template_name = template_name
85
17
  @planned_duration = planned_duration
86
18
  @steps = steps
87
19
  @custom_fields = custom_fields
88
20
  @third_party_id = third_party_id
89
- @assigned_to = assigned_to
21
+ @assigned_to_id = assigned_to_id
90
22
  @planned_start_at = planned_start_at
91
23
  end
92
-
93
- def is_new?
94
- self.id == nil
95
- end
96
-
24
+
97
25
  def to_hash
98
26
  job_hash = {
99
27
  :job => {
@@ -109,14 +37,49 @@ module VWorkApp
109
37
  end
110
38
 
111
39
  def self.from_hash(attributes)
112
- j = Job.new(attributes["customer_name"], attributes["template_name"], attributes["planned_duration"], attributes["steps"].map { |h| Step.from_hash(h) }, nil, attributes["id"], attributes["third_party_id"])
113
- j.custom_fields = attributes["custom_fields"].map { |h| CustomField.from_hash(h) } if attributes["custom_fields"]
114
- j
40
+ job = Job.new(attributes["customer_name"], attributes["template_name"], attributes["planned_duration"],
41
+ attributes["steps"].map { |h| Step.from_hash(h) }, nil, attributes["id"], attributes["third_party_id"])
42
+ job.custom_fields = attributes["custom_fields"].map { |h| CustomField.from_hash(h) } if attributes["custom_fields"]
43
+
44
+ job.assigned_to_id = attributes["worker_id"]
45
+ job.planned_start_at = attributes["planned_start_at"]
46
+ job.progress_state = attributes["progress_state"]
47
+
48
+ job
115
49
  end
116
50
 
51
+ def is_new?
52
+ self.id == nil
53
+ end
54
+
55
+ def assigned_to
56
+ return nil if @assigned_to_id.nil?
57
+ @assigned_to ||= Worker.show(self.assigned_to_id)
58
+ end
59
+
60
+ def ==(other)
61
+ attributes_eql?(other, [
62
+ :id, :third_party_id, :customer_name, :template_name, :planned_duration, :planned_start_at,
63
+ :assigned_to_id, :steps, :custom_fields
64
+ ])
65
+ end
66
+
67
+ #---------------
68
+ # REST Methods
69
+ #---------------
70
+
117
71
  def create
118
- res = self.class.post("/jobs", :body => self.to_hash, :query => { :api_key => VWorkApp.api_key })
119
- res.success? ? res : self.class.bad_response(res)
72
+ perform(:post, "/jobs.xml", {}, self.to_hash) do |res|
73
+ Job.from_hash(res["job"])
74
+ end
75
+
76
+ # res = self.class.post("/jobs", :body => self.to_hash, :query => { :api_key => VWorkApp.api_key })
77
+ # if res.success?
78
+ # self.id = res["job"]["id"]
79
+ # self
80
+ # else
81
+ # self.class.bad_response(res)
82
+ # end
120
83
  end
121
84
 
122
85
  def update(id, attributes)
@@ -124,39 +87,82 @@ module VWorkApp
124
87
  res.success? ? res : bad_response(res)
125
88
  end
126
89
 
127
- def self.all
128
- find
90
+ def delete(use_third_party_id = false)
91
+ perform(:delete, "/jobs/#{id}.xml", { :use_third_party_id => use_third_party_id })
92
+ end
93
+
94
+ def self.show(id, use_third_party_id = false)
95
+ perform(:get, "/jobs/#{id}.xml", :use_third_party_id => use_third_party_id) do |res|
96
+ Job.from_hash(res["job"])
97
+ end
98
+ # raw = get("/jobs/#{id}.xml", :query => { :api_key => VWorkApp.api_key, :use_third_party_id => use_third_party_id })
99
+ # case res
100
+ # when Net::HTTPOK
101
+ # Job.from_hash(raw["job"])
102
+ # when Net::HTTPNotFound
103
+ # nil
104
+ # else
105
+ # bad_response(res)
106
+ # end
129
107
  end
130
108
 
131
- ##
132
- # Returns jobs that match the given query options. Valid options are:
133
- # - :state — Filter by state. Possible values: unallocated, allocated, assigned, not_started, started, completed.
134
- # - :start_at — Filter by planned_start_at/last_action_time (must also give end_at).
135
- # - :end_at — Filter by planned_start_at/last_action_time (must also give start_at).
136
- # - :customer_name — Filter by customer name.
137
- # - :worker_id — Filter by assigned worker.
138
- # - :worker_third_party_id — Filter by assigned worker third party id.
139
- # - :per_page — The number of records to return per page.
140
- # - :page — The page of records to return.
141
- # - :third_party_id — The third_party_id associated with the job.
142
109
  def self.find(options={})
143
- p options
144
110
  third_party_id = options.delete(:third_party_id)
145
- options[:search] = "@third_party_id=#{third_party_id}" if (third_party_id)
111
+ options[:search] = "@third_party_id=#{third_party_id.to_s}" if (third_party_id)
146
112
  options[:api_key] = VWorkApp.api_key
147
113
 
148
114
  raw = get("/jobs.xml", :query => options)
149
115
  raw["jobs"].map { |h| Job.from_hash(h) }
150
116
  end
117
+
118
+ end
119
+
120
+ class Step
121
+ include AttributeEquality
122
+ attr_accessor :name, :location
123
+
124
+ def initialize(name, location = nil)
125
+ @name = name
126
+ @location = location
127
+ end
128
+
129
+ def to_hash
130
+ h = { :name => name }
131
+ h.merge!({ :location => location.to_hash }) if location
132
+ h
133
+ end
134
+
135
+ def self.from_hash(attributes)
136
+ Step.new(attributes["name"], Location.from_hash(attributes["location"]))
137
+ end
151
138
 
152
- def self.show(id)
153
- get("/jobs/#{id}.xml", :query => { :api_key => VWorkApp.api_key })
139
+ def ==(other)
140
+ attributes_eql?(other, [:name, :location])
154
141
  end
155
142
 
156
- def self.delete(id)
157
-
143
+ end
144
+
145
+ class CustomField
146
+ include AttributeEquality
147
+ attr_accessor :name, :value
148
+
149
+ def initialize(name, value)
150
+ @name = name
151
+ @value = value
158
152
  end
159
-
153
+
154
+ def to_hash
155
+ { :name => name.to_s, :value => value.to_s }
156
+ end
157
+
158
+ def self.from_hash(attributes)
159
+ CustomField.new(attributes["name"], attributes["value"])
160
+ end
161
+
162
+ def ==(other)
163
+ attributes_eql?(other, [:name, :value])
164
+ end
165
+
160
166
  end
161
167
 
162
168
  end
@@ -0,0 +1,40 @@
1
+ module VWorkApp
2
+
3
+ class Location
4
+ include AttributeEquality
5
+ attr_accessor :formatted_address, :lat, :lng
6
+
7
+ def initialize(formatted_address, lat, lng)
8
+ @formatted_address = formatted_address
9
+ @lat = lat
10
+ @lng = lng
11
+ end
12
+
13
+ def self.from_address(address, region = :us)
14
+ loc = Location.geocode(address, region).first.geometry.location
15
+ self.new(address, loc.lat, loc.lng)
16
+ end
17
+
18
+ def to_hash
19
+ { :formatted_address => formatted_address, :lat => lat, :lng => lng }
20
+ end
21
+
22
+ def self.from_hash(attributes)
23
+ return nil unless attributes
24
+ Location.new(attributes["formatted_address"], attributes["lat"], attributes["lng"])
25
+ end
26
+
27
+ def ==(other)
28
+ attributes_eql?(other, [:lat, :lng])
29
+ end
30
+
31
+ private
32
+
33
+ def self.geocode(address, region)
34
+ @gecoder ||= GCoder.connect(:storage => :heap)
35
+ @gecoder[address, { :region => region }]
36
+ end
37
+
38
+ end
39
+
40
+ end
@@ -1,51 +1,88 @@
1
1
  module VWorkApp
2
2
 
3
- class Telemetry
4
- attr_accessor :lat, :lng, :recorded_at, :heading, :speed
5
- def initialize (lat, lng, recorded_at, heading, speed)
6
- @lat = lat
7
- @lng = lng
8
- @recorded_at = recorded_at
9
- @heading = heading
10
- @speed = speed
11
- end
12
-
13
- def self.from_hash(attributes)
14
- @lat = attributes["lat"]
15
- @lng = attributes["lng"]
16
- @recorded_at = attributes["recorded_at"]
17
- @heading = attributes["heading"]
18
- @speed = attributes["speed"]
19
- end
20
-
21
- end
22
-
23
- class Worker < Base
24
-
3
+ class Worker < Base
25
4
  attr_accessor :id, :name, :email, :latest_telemetry, :third_party_id
26
5
 
6
+ #---------------
7
+ # Object Methods
8
+ #---------------
9
+
27
10
  def initialize(name, email, id = nil, third_party_id = nil)
28
11
  @name = name
29
12
  @email = email
30
13
  @id = id
31
14
  @third_party_id = third_party_id
32
15
  end
16
+
17
+ def self.from_hash(attributes)
18
+ worker = Worker.new(attributes["name"], attributes["email"], attributes["id"], attributes["third_party_id"])
19
+ worker.latest_telemetry = Telemetry.from_hash(attributes["latest_telemetry"]) if attributes["latest_telemetry"]
20
+ worker
21
+ end
22
+
23
+ def to_hash
24
+ worker_hash = {
25
+ :worker => {
26
+ :name => self.name,
27
+ :email => self.email
28
+ }
29
+ }
30
+ worker_hash[:worker][:third_party_id] = self.third_party_id if third_party_id
31
+ worker_hash
32
+ end
33
33
 
34
- def self.all
35
- find
34
+ def ==(other)
35
+ attributes_eql?(other, [:id, :name, :email, :third_party_id])
36
36
  end
37
+
38
+ #---------------
39
+ # REST Methods
40
+ #---------------
41
+
42
+ def create
43
+ perform(:post, "/workers", {}, self.to_hash) do |res|
44
+ Worker.from_hash(res["worker"])
45
+ end
46
+ end
47
+
48
+ def update(use_third_party_id = false)
49
+ perform(:put, "/workers/#{id}.xml", { :use_third_party_id => use_third_party_id }, self.to_hash)
50
+ end
51
+
52
+ def delete(use_third_party_id = false)
53
+ perform(:delete, "/workers/#{id}.xml", { :use_third_party_id => use_third_party_id })
54
+ end
55
+
56
+ def self.show(id, use_third_party_id = false)
57
+ perform(:get, "/workers/#{id}.xml", :use_third_party_id => use_third_party_id) do |res|
58
+ Worker.from_hash(res["worker"])
59
+ end
60
+ end
37
61
 
38
62
  def self.find
39
- raw = get("/workers.xml", :query => { :api_key => VWorkApp.api_key })["workers"]
40
- raw.map { |h| Worker.from_hash(h) }
63
+ self.perform(:get, "/workers.xml") do |res|
64
+ res["workers"].map { |h| Worker.from_hash(h) }
65
+ end
66
+ end
67
+
68
+ end
69
+
70
+ class Telemetry
71
+ attr_accessor :lat, :lng, :recorded_at, :heading, :speed
72
+
73
+ def initialize (lat, lng, recorded_at, heading, speed)
74
+ @lat = lat
75
+ @lng = lng
76
+ @recorded_at = recorded_at
77
+ @heading = heading
78
+ @speed = speed
41
79
  end
42
80
 
43
81
  def self.from_hash(attributes)
44
- w = Worker.new(attributes["name"], attributes["email"], attributes["id"], attributes["third_party_id"])
45
- w.latest_telemetry = Telemetry.from_hash(attributes["latest_telemetry"]) if attributes["latest_telemetry"]
46
- w
82
+ Telemetry.new(attributes["lat"], attributes["lng"], attributes["recorded_at"], attributes["heading"], attributes["speed"])
47
83
  end
48
84
 
49
85
  end
50
86
 
87
+
51
88
  end
@@ -0,0 +1,152 @@
1
+ require "vworkapp_ruby"
2
+
3
+ describe VW::Customer do
4
+
5
+ before(:all) do
6
+ VW::Customer.base_uri 'api.staging.vworkapp.com/api/2.0'
7
+ VW.api_key = "AtuogECLCV2R7uT-fkPg"
8
+ end
9
+
10
+ context "Without a known customer" do
11
+
12
+ describe "#Equals" do
13
+
14
+ it "Is equal to another customer if it has the same key attributes" do
15
+ customer_1 = VW::Customer.new("Joe's Baked Goods", 100, 200,
16
+ VW::Contact.new("Joe", "Fisher", "415-465-8888", "415-465-9999", "joe@bakary.com"),
17
+ VW::Contact.new("Bob", "Jones", "021-465-2342", "233-233-1242", "bob.jones@jones.com")
18
+ )
19
+ customer_2 = VW::Customer.new("Joe's Baked Goods", 100, 200,
20
+ VW::Contact.new("Joe", "Fisher", "415-465-8888", "415-465-9999", "joe@bakary.com"),
21
+ VW::Contact.new("Bob", "Jones", "021-465-2342", "233-233-1242", "bob.jones@jones.com")
22
+ )
23
+ customer_1.should == customer_2
24
+ end
25
+
26
+ it "Isn't equal to another worker if doesn't share the key attributes" do
27
+ customer_1 = VW::Customer.new("Joe's Baked Goods", 100, 200,
28
+ VW::Contact.new("Joe", "Fisher", "415-465-8888", "415-465-9999", "joe@bakary.com"),
29
+ VW::Contact.new("Bob", "Jones", "021-465-2342", "233-233-1242", "bob.jones@jones.com")
30
+ )
31
+ customer_2 = VW::Customer.new("Joe's Baked Goods", 100, 200,
32
+ VW::Contact.new("Joe", "Fisher", "415-465-8888", "415-465-9999", "joe@bakary.com"),
33
+ VW::Contact.new("Jeff", "Jones", "021-465-2342", "233-233-1242", "bob.jones@jones.com")
34
+ )
35
+ customer_1.should_not == customer_2
36
+ end
37
+
38
+ end
39
+
40
+ describe "#Create" do
41
+
42
+ it "Assigns the new customer an id" do
43
+ @customer = VW::Customer.new("Joe's Baked Goods")
44
+ @customer = @customer.create
45
+ @customer.id.should_not be_nil
46
+ end
47
+
48
+ it "Creates a customer" do
49
+ @customer = VW::Customer.new("Joe's Baked Goods", nil, "My ID")
50
+ @customer = @customer.create
51
+
52
+ r_cust = VW::Customer.show(@customer.id)
53
+ r_cust.name.should == @customer.name
54
+ r_cust.third_party_id.should == @customer.third_party_id
55
+ end
56
+
57
+ it "Creates a customer with a billing and delivery contact" do
58
+ site_contact = VW::Contact.new("Joe", "Fisher", "415-465-8888", "415-465-9999", "joe@bakary.com")
59
+ billing_contact = VW::Contact.new("Felix", "Smith")
60
+ @customer = VW::Customer.new("Joe's Baked Goods", nil, "My ID", site_contact, billing_contact)
61
+ @customer = @customer.create
62
+
63
+ r_cust = VW::Customer.show(@customer.id)
64
+
65
+ r_cust.site_contact.should == site_contact
66
+ r_cust.billing_contact.should == billing_contact
67
+ end
68
+
69
+ it "Creates a customer with a contact location" do
70
+ pending "Can't pass a location object in yet. API should support this"
71
+ site = VW::Location.from_address("880 Harrison St, SF, USA")
72
+ @customer = VW::Customer.new("Joe's Baked Goods", nil, "My ID", VW::Contact.new("Joe", "Fisher", nil, nil, nil, site))
73
+ @customer = @customer.create
74
+
75
+ r_cust = VW::Customer.show(@customer.id)
76
+ r_cust.site_contact.location.should == site
77
+ end
78
+
79
+ end
80
+
81
+ after(:each) do
82
+ @customer.delete if @customer
83
+ end
84
+
85
+ end
86
+
87
+ context "With a known customer" do
88
+ before(:each) do
89
+ @customer = VW::Customer.new("Joe's Baked Goods")
90
+ @customer = @customer.create
91
+ end
92
+
93
+ after(:each) do
94
+ @customer.delete
95
+ end
96
+
97
+ describe "#Show" do
98
+ it "Returns the customer" do
99
+ r_cust = VW::Customer.show(@customer.id)
100
+ r_cust.name.should == "Joe's Baked Goods"
101
+ end
102
+
103
+ it "Returns nil if not found" do
104
+ r_customer = VW::Customer.show(-1)
105
+ r_customer.should be_nil
106
+ end
107
+ end
108
+
109
+ describe "#Update" do
110
+
111
+ it "Updates a customer's primary details" do
112
+ @customer.name = "Jeff's Canned Beans"
113
+ @customer.third_party_id = "My Other ID"
114
+ @customer.update
115
+ r_cust = VW::Customer.show(@customer.id)
116
+ r_cust.name.should == "Jeff's Canned Beans"
117
+ r_cust.third_party_id.should == "My Other ID"
118
+ end
119
+
120
+ it "Updates a customers site and billing contacts" do
121
+ site_contact = VW::Contact.new("Joe", "Fisher", "415-465-8888", "415-465-9999", "joe@bakary.com")
122
+ billing_contact = VW::Contact.new("Felix", "Smith")
123
+ @customer.site_contact = site_contact
124
+ @customer.billing_contact = billing_contact
125
+ @customer.update
126
+
127
+ r_cust = VW::Customer.show(@customer.id)
128
+ r_cust.site_contact.should == site_contact
129
+ r_cust.billing_contact.should == billing_contact
130
+ end
131
+
132
+ end
133
+
134
+ describe "#Delete" do
135
+ it "Deletes the customer" do
136
+ @customer.delete
137
+ r_customer = VW::Customer.show(@customer.id)
138
+ r_customer.should be_nil
139
+ end
140
+ end
141
+
142
+ describe "#Find" do
143
+ it "Finds all customers" do
144
+ results = VW::Customer.find
145
+ results.should be_instance_of(Array)
146
+ results.should include(@customer)
147
+ end
148
+ end
149
+
150
+ end
151
+
152
+ end
data/spec/job_spec.rb ADDED
@@ -0,0 +1,199 @@
1
+ require "vworkapp_ruby"
2
+
3
+ describe VW::Job do
4
+
5
+ before(:all) do
6
+ VW::Job.base_uri 'api.staging.vworkapp.com/api/2.0'
7
+ VW.api_key = "AtuogECLCV2R7uT-fkPg"
8
+ end
9
+
10
+ context "Without a known job" do
11
+
12
+ describe "#Equals" do
13
+
14
+ it "Is equal to another job if it has the same attributes, steps, and custom_fields" do
15
+ job_1 = VW::Job.new("Joe", "Std Delivery", 60,
16
+ [
17
+ VW::Step.new("Start", VWorkApp::Location.new("880 Harrison St", 37.779536, -122.401503)),
18
+ VW::Step.new("End", VWorkApp::Location.new("Other Street", 38.779536, -123.401503))
19
+ ],
20
+ [
21
+ VW::CustomField.new("Note", "Hi There!")
22
+ ],
23
+ 100, 202, 101, Date.new(2001,2,3)
24
+ )
25
+ job_2 = VW::Job.new("Joe", "Std Delivery", 60,
26
+ [
27
+ VW::Step.new("Start", VWorkApp::Location.new("880 Harrison St!", 37.779536, -122.401503)),
28
+ VW::Step.new("End", VWorkApp::Location.new("Other Street", 38.779536, -123.401503))
29
+ ],
30
+ [
31
+ VW::CustomField.new("Note", "Hi There!")
32
+ ],
33
+ 100, 202, 101, Date.new(2001,2,3)
34
+ )
35
+ job_1.should == job_2
36
+ end
37
+
38
+ it "Isn't equal to another job if doesn't share the key attributes" do
39
+ job_1 = VW::Job.new("Joe", "Std Delivery", 60, nil, nil, 100, 202, 101, Date.new(2001,2,3))
40
+ job_2 = VW::Job.new("Joe", "Std Delivery", 60, nil, nil, 100, 202, 101, Date.new(2001,4,3))
41
+ job_1.should_not == job_2
42
+ end
43
+
44
+ it "Isn't equal to another job if doesn't share the same steps" do
45
+ job_1 = VW::Job.new("Joe", "Std Delivery", 60, [
46
+ VW::Step.new("Start", VWorkApp::Location.new("880 Harrison St", 37.779536, -122.401503)),
47
+ VW::Step.new("End", VWorkApp::Location.new("Other Street", 38.779536, -122.401503))
48
+ ])
49
+ job_2 = VW::Job.new("Joe", "Std Delivery", 60, [
50
+ VW::Step.new("Start", VWorkApp::Location.new("880 Harrison St", 37.779536, -122.401503)),
51
+ VW::Step.new("End", VWorkApp::Location.new("DIFFERENT", 38.779536, 100))
52
+ ])
53
+ job_1.should_not == job_2
54
+ end
55
+
56
+ it "Isn't equal to another job if doesn't share the same custom fields" do
57
+ job_1 = VW::Job.new("Joe", "Std Delivery", 60, nil, [
58
+ VW::CustomField.new("Note1", "Value1"),
59
+ VW::CustomField.new("Note2", "Value2"),
60
+ ])
61
+ job_2 = VW::Job.new("Joe", "Std Delivery", 60, nil, [
62
+ VW::CustomField.new("Note1", "Value1"),
63
+ VW::CustomField.new("Note2", "DIFFERENT"),
64
+ ])
65
+ job_1.should_not == job_2
66
+ end
67
+
68
+ end
69
+
70
+ describe "#Create" do
71
+
72
+ it "Assigns the new job an id" do
73
+ @job = VW::Job.new("Joe", "Std Delivery", 60,
74
+ [
75
+ VW::Step.new("Start", VWorkApp::Location.new("880 Harrison St", 37.779536, -122.401503)),
76
+ VW::Step.new("End", VWorkApp::Location.new("Other Street", 38.779536, -123.401503))
77
+ ],
78
+ [
79
+ VW::CustomField.new("Note", "Hi There!")
80
+ ],
81
+ 100, 202, 101, Date.new(2001,2,3)
82
+ )
83
+
84
+ @job = @job.create
85
+ @job.id.should_not be_nil
86
+ end
87
+
88
+ it "Creates an unassigned job" do
89
+ @job = VW::Job.new("Joe", "Std Delivery", 60,
90
+ [
91
+ VW::Step.new("Start", VWorkApp::Location.new("880 Harrison St", 37.779536, -122.401503)),
92
+ VW::Step.new("End", VWorkApp::Location.new("Other Street", 38.779536, -123.401503))
93
+ ])
94
+ @job = @job.create
95
+ r_job = VW::Job.show(@job.id)
96
+ r_job.customer_name.should == @job.customer_name
97
+ r_job.template_name.should == @job.template_name
98
+ r_job.planned_duration.should == @job.planned_duration
99
+ r_job.steps.should == @job.steps
100
+ end
101
+
102
+ it "Creates an unassigned job with Custom Fields" do
103
+ @job = VW::Job.new("Joe", "Std Delivery", 60,
104
+ [
105
+ VW::Step.new("Start", VWorkApp::Location.new("880 Harrison St", 37.779536, -122.401503)),
106
+ VW::Step.new("End", VWorkApp::Location.new("Other Street", 38.779536, -123.401503))
107
+ ],
108
+ [
109
+ VW::CustomField.new("Note1", "Value1"),
110
+ VW::CustomField.new("Note2", "Value2"),
111
+ ]
112
+ )
113
+ @job = @job.create
114
+ r_job = VW::Job.show(@job.id)
115
+ r_job.custom_fields.should == @job.custom_fields
116
+ end
117
+
118
+ it "Creates and assigns a job" do
119
+ @worker = VW::Worker.new("Joe", "joe@example.com")
120
+ @worker = @worker.create
121
+
122
+ @job = VW::Job.new("Joe", "Std Delivery", 60,
123
+ [
124
+ VW::Step.new("Start", VWorkApp::Location.new("880 Harrison St", 37.779536, -122.401503)),
125
+ VW::Step.new("End", VWorkApp::Location.new("Other Street", 38.779536, -123.401503))
126
+ ], nil, nil, @worker.id, DateTime.parse("2012-12-25 16:30"))
127
+ @job = @job.create
128
+ r_job = VW::Job.show(@job.id)
129
+
130
+ r_job.worker_id.should == @worker.id
131
+ r_job.planned_start_time.should == DateTime.parse("2012-12-25 16:30")
132
+ end
133
+
134
+ end
135
+
136
+ after(:each) do
137
+ @job.delete if @job
138
+ @worker.delete if @worker
139
+ end
140
+
141
+ end
142
+
143
+ # context "With a known job" do
144
+ # before(:each) do
145
+ # @worker = VW::Worker.new("Joe", "joe@example.com")
146
+ # @worker = @worker.create
147
+ # end
148
+ #
149
+ # after(:each) do
150
+ # @worker.delete
151
+ # end
152
+ #
153
+ # describe "#show" do
154
+ # it "Returns the worker" do
155
+ # r_worker = VW::Worker.show(@worker.id)
156
+ # r_worker.name.should == "Joe"
157
+ # r_worker.email.should == "joe@example.com"
158
+ # end
159
+ #
160
+ # it "Returns nil if not found" do
161
+ # pending("Bug in vWorkApp. Should be returning a 404 but isn't")
162
+ # r_worker = VW::Worker.show(-1)
163
+ # r_worker.should be_nil
164
+ # end
165
+ # end
166
+ #
167
+ # describe "#update" do
168
+ # it "Updates the worker" do
169
+ # @worker.name = "Joe2"
170
+ # @worker.email = "joe2@example.com"
171
+ # @worker.update
172
+ # r_worker = VW::Worker.show(@worker.id)
173
+ # r_worker.name.should == "Joe2"
174
+ # r_worker.email.should == "joe2@example.com"
175
+ # end
176
+ # end
177
+ #
178
+ # describe "#delete" do
179
+ # it "Deletes the worker" do
180
+ # @worker.delete
181
+ # # XXX Can't verify until #show is fixed
182
+ # # r_worker = VW::Worker.show(@worker.id)
183
+ # # r_worker.should be_nil
184
+ # end
185
+ # end
186
+ #
187
+ # describe "#find" do
188
+ # it "Finds all workers" do
189
+ # results = VW::Worker.find
190
+ # results.should be_instance_of(Array)
191
+ # results.should include(@worker)
192
+ # end
193
+ # end
194
+ #
195
+ # end
196
+
197
+
198
+
199
+ end
@@ -0,0 +1,108 @@
1
+ require "vworkapp_ruby"
2
+
3
+ describe VW::Worker do
4
+
5
+ before(:all) do
6
+ VW::Worker.base_uri 'api.staging.vworkapp.com/api/2.0'
7
+ VW.api_key = "AtuogECLCV2R7uT-fkPg"
8
+ end
9
+
10
+ context "Without a known worker" do
11
+
12
+ describe "#Equal" do
13
+
14
+ it "Is equal to another worker if it has the same key attributes" do
15
+ worker_1 = VW::Worker.new("Joe", "joe@example.com", 100, 200)
16
+ worker_2 = VW::Worker.new("Joe", "joe@example.com", 100, 200)
17
+ worker_1.should == worker_2
18
+ end
19
+
20
+ it "Isn't equal to another worker if doesn't share the key attributes" do
21
+ worker_1 = VW::Worker.new("Joe", "joe@example.com", 100, 200)
22
+ worker_2 = VW::Worker.new("Joe", "joe@example.com", 100, 202)
23
+ worker_1.should_not == worker_2
24
+ end
25
+
26
+ end
27
+
28
+ describe "#Create" do
29
+
30
+ it "Assigns the new worker an id" do
31
+ @worker = VW::Worker.new("Joe", "joe@example.com")
32
+ @worker = @worker.create
33
+ @worker.id.should_not be_nil
34
+ end
35
+
36
+ it "Creates a worker" do
37
+ @worker = VW::Worker.new("Joe", "joe@example.com")
38
+ @worker = @worker.create
39
+ r_worker = VW::Worker.show(@worker.id)
40
+ r_worker.name.should == @worker.name
41
+ r_worker.email.should == @worker.email
42
+ end
43
+
44
+ end
45
+
46
+ after(:each) do
47
+ @worker.delete if @worker
48
+ end
49
+
50
+ end
51
+
52
+ context "With a known worker" do
53
+ before(:each) do
54
+ @worker = VW::Worker.new("Joe", "joe@example.com")
55
+ @worker = @worker.create
56
+ end
57
+
58
+ after(:each) do
59
+ @worker.delete
60
+ end
61
+
62
+ describe "#Show" do
63
+ it "Returns the worker" do
64
+ r_worker = VW::Worker.show(@worker.id)
65
+ r_worker.name.should == "Joe"
66
+ r_worker.email.should == "joe@example.com"
67
+ end
68
+
69
+ it "Returns nil if not found" do
70
+ pending("Bug in vWorkApp. Should be returning a 404 but isn't")
71
+ r_worker = VW::Worker.show(-1)
72
+ r_worker.should be_nil
73
+ end
74
+ end
75
+
76
+ describe "#Update" do
77
+ it "Updates the worker" do
78
+ @worker.name = "Joe2"
79
+ @worker.email = "joe2@example.com"
80
+ @worker.update
81
+ r_worker = VW::Worker.show(@worker.id)
82
+ r_worker.name.should == "Joe2"
83
+ r_worker.email.should == "joe2@example.com"
84
+ end
85
+ end
86
+
87
+ describe "#Delete" do
88
+ it "Deletes the worker" do
89
+ @worker.delete
90
+ # XXX Can't verify until #show is fixed
91
+ # r_worker = VW::Worker.show(@worker.id)
92
+ # r_worker.should be_nil
93
+ end
94
+ end
95
+
96
+ describe "#Find" do
97
+ it "Finds all workers" do
98
+ results = VW::Worker.find
99
+ results.should be_instance_of(Array)
100
+ results.should include(@worker)
101
+ end
102
+ end
103
+
104
+ end
105
+
106
+
107
+
108
+ end
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = "vworkapp_ruby"
3
- s.version = "0.0.1"
3
+ s.version = "0.1.0"
4
4
  s.platform = Gem::Platform::RUBY
5
5
  s.authors = ["vWorkApp Inc.", "Aish Fenton"]
6
6
  s.email = ["info@vworkapp.com"]
@@ -12,6 +12,7 @@ Gem::Specification.new do |s|
12
12
 
13
13
  s.add_dependency "httparty"
14
14
  s.add_dependency "gcoder"
15
+
15
16
  s.add_development_dependency "rspec"
16
17
 
17
18
  s.files = `git ls-files`.split("\n") rescue ''
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: vworkapp_ruby
3
3
  version: !ruby/object:Gem::Version
4
- hash: 29
4
+ hash: 27
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
- - 0
9
8
  - 1
10
- version: 0.0.1
9
+ - 0
10
+ version: 0.1.0
11
11
  platform: ruby
12
12
  authors:
13
13
  - vWorkApp Inc.
@@ -16,7 +16,7 @@ autorequire:
16
16
  bindir: bin
17
17
  cert_chain: []
18
18
 
19
- date: 2011-10-03 00:00:00 Z
19
+ date: 2012-01-20 00:00:00 Z
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency
22
22
  name: httparty
@@ -70,18 +70,23 @@ extensions: []
70
70
  extra_rdoc_files: []
71
71
 
72
72
  files:
73
+ - .gitignore
73
74
  - Gemfile
75
+ - Gemfile.lock
74
76
  - README.md
75
77
  - examples/create_job.rb
76
78
  - examples/print_jobs.rb
77
79
  - lib/vworkapp_ruby.rb
78
80
  - lib/vworkapp_ruby/base.rb
79
- - lib/vworkapp_ruby/cli/job.rb
80
81
  - lib/vworkapp_ruby/customer.rb
81
82
  - lib/vworkapp_ruby/httparty_monkey_patch.rb
82
83
  - lib/vworkapp_ruby/job.rb
84
+ - lib/vworkapp_ruby/location.rb
83
85
  - lib/vworkapp_ruby/response_error.rb
84
86
  - lib/vworkapp_ruby/worker.rb
87
+ - spec/customer_spec.rb
88
+ - spec/job_spec.rb
89
+ - spec/worker_spec.rb
85
90
  - vworkapp_ruby.gemspec
86
91
  homepage: http://api.vworkapp.com/api/
87
92
  licenses: []
@@ -114,7 +119,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
114
119
  requirements: []
115
120
 
116
121
  rubyforge_project:
117
- rubygems_version: 1.8.10
122
+ rubygems_version: 1.8.11
118
123
  signing_key:
119
124
  specification_version: 3
120
125
  summary: Simple interface to vWorkApp's api
@@ -1,5 +0,0 @@
1
- vwk-job find -w 12 -c Bob
2
- vwk-job show -w 12 -c Bob
3
- vwk-job create -worker 12 --customer Bob --template Delivery --start-time --duration 12 --cf name1:value1,name1:value1
4
- vwk-job list -w 12 -c Bob
5
- vwk-job delete -w 12 -c Bob