vworkapp_ruby 0.1.0 → 0.7.0
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile.lock +1 -1
- data/README.md +79 -12
- data/examples/example_1.rb +32 -0
- data/examples/example_2.rb +23 -0
- data/examples/example_3/Gemfile +5 -0
- data/examples/example_3/Gemfile.lock +35 -0
- data/examples/example_3/README.md +26 -0
- data/examples/example_3/public/style.css +25 -0
- data/examples/example_3/public/truck.png +0 -0
- data/examples/example_3/server.rb +41 -0
- data/examples/example_3/views/index.haml +47 -0
- data/lib/vworkapp_ruby.rb +13 -3
- data/lib/vworkapp_ruby/base/base.rb +173 -0
- data/lib/vworkapp_ruby/{httparty_monkey_patch.rb → base/httparty_monkey_patch.rb} +2 -4
- data/lib/vworkapp_ruby/base/resource.rb +105 -0
- data/lib/vworkapp_ruby/base/response_error.rb +26 -0
- data/lib/vworkapp_ruby/contact.rb +11 -0
- data/lib/vworkapp_ruby/custom_field.rb +11 -0
- data/lib/vworkapp_ruby/customer.rb +9 -97
- data/lib/vworkapp_ruby/job.rb +29 -146
- data/lib/vworkapp_ruby/location.rb +6 -23
- data/lib/vworkapp_ruby/step.rb +11 -0
- data/lib/vworkapp_ruby/telemetry.rb +6 -0
- data/lib/vworkapp_ruby/worker.rb +4 -81
- data/spec/base_spec.rb +174 -0
- data/spec/customer_spec.rb +30 -46
- data/spec/job_spec.rb +189 -143
- data/spec/resource_spec.rb +37 -0
- data/spec/support/active_model_lint.rb +19 -0
- data/spec/worker_spec.rb +6 -25
- data/vworkapp_ruby-0.1.0.gem +0 -0
- data/vworkapp_ruby.gemspec +5 -4
- metadata +46 -16
- data/examples/create_job.rb +0 -34
- data/examples/print_jobs.rb +0 -31
- data/lib/vworkapp_ruby/base.rb +0 -72
- data/lib/vworkapp_ruby/response_error.rb +0 -35
Binary file
|
data/vworkapp_ruby.gemspec
CHANGED
@@ -1,15 +1,16 @@
|
|
1
1
|
Gem::Specification.new do |s|
|
2
2
|
s.name = "vworkapp_ruby"
|
3
|
-
s.version = "0.
|
3
|
+
s.version = "0.7.0"
|
4
4
|
s.platform = Gem::Platform::RUBY
|
5
5
|
s.authors = ["vWorkApp Inc.", "Aish Fenton"]
|
6
6
|
s.email = ["info@vworkapp.com"]
|
7
|
-
s.homepage = "http://
|
8
|
-
s.summary = %q{
|
9
|
-
s.description = %q{
|
7
|
+
s.homepage = "http://developer.vworkapp.com"
|
8
|
+
s.summary = %q{A ruby wrapper for vWorkApp's API}
|
9
|
+
s.description = %q{A ruby wrapper for vWorkApp's API}
|
10
10
|
|
11
11
|
s.required_rubygems_version = ">= 1.3.6"
|
12
12
|
|
13
|
+
s.add_dependency "active_model"
|
13
14
|
s.add_dependency "httparty"
|
14
15
|
s.add_dependency "gcoder"
|
15
16
|
|
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:
|
4
|
+
hash: 3
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
|
-
-
|
8
|
+
- 7
|
9
9
|
- 0
|
10
|
-
version: 0.
|
10
|
+
version: 0.7.0
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- vWorkApp Inc.
|
@@ -16,10 +16,10 @@ autorequire:
|
|
16
16
|
bindir: bin
|
17
17
|
cert_chain: []
|
18
18
|
|
19
|
-
date: 2012-
|
19
|
+
date: 2012-02-02 00:00:00 Z
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|
22
|
-
name:
|
22
|
+
name: active_model
|
23
23
|
prerelease: false
|
24
24
|
requirement: &id001 !ruby/object:Gem::Requirement
|
25
25
|
none: false
|
@@ -33,7 +33,7 @@ dependencies:
|
|
33
33
|
type: :runtime
|
34
34
|
version_requirements: *id001
|
35
35
|
- !ruby/object:Gem::Dependency
|
36
|
-
name:
|
36
|
+
name: httparty
|
37
37
|
prerelease: false
|
38
38
|
requirement: &id002 !ruby/object:Gem::Requirement
|
39
39
|
none: false
|
@@ -47,7 +47,7 @@ dependencies:
|
|
47
47
|
type: :runtime
|
48
48
|
version_requirements: *id002
|
49
49
|
- !ruby/object:Gem::Dependency
|
50
|
-
name:
|
50
|
+
name: gcoder
|
51
51
|
prerelease: false
|
52
52
|
requirement: &id003 !ruby/object:Gem::Requirement
|
53
53
|
none: false
|
@@ -58,9 +58,23 @@ dependencies:
|
|
58
58
|
segments:
|
59
59
|
- 0
|
60
60
|
version: "0"
|
61
|
-
type: :
|
61
|
+
type: :runtime
|
62
62
|
version_requirements: *id003
|
63
|
-
|
63
|
+
- !ruby/object:Gem::Dependency
|
64
|
+
name: rspec
|
65
|
+
prerelease: false
|
66
|
+
requirement: &id004 !ruby/object:Gem::Requirement
|
67
|
+
none: false
|
68
|
+
requirements:
|
69
|
+
- - ">="
|
70
|
+
- !ruby/object:Gem::Version
|
71
|
+
hash: 3
|
72
|
+
segments:
|
73
|
+
- 0
|
74
|
+
version: "0"
|
75
|
+
type: :development
|
76
|
+
version_requirements: *id004
|
77
|
+
description: A ruby wrapper for vWorkApp's API
|
64
78
|
email:
|
65
79
|
- info@vworkapp.com
|
66
80
|
executables: []
|
@@ -74,21 +88,37 @@ files:
|
|
74
88
|
- Gemfile
|
75
89
|
- Gemfile.lock
|
76
90
|
- README.md
|
77
|
-
- examples/
|
78
|
-
- examples/
|
91
|
+
- examples/example_1.rb
|
92
|
+
- examples/example_2.rb
|
93
|
+
- examples/example_3/Gemfile
|
94
|
+
- examples/example_3/Gemfile.lock
|
95
|
+
- examples/example_3/README.md
|
96
|
+
- examples/example_3/public/style.css
|
97
|
+
- examples/example_3/public/truck.png
|
98
|
+
- examples/example_3/server.rb
|
99
|
+
- examples/example_3/views/index.haml
|
79
100
|
- lib/vworkapp_ruby.rb
|
80
|
-
- lib/vworkapp_ruby/base.rb
|
101
|
+
- lib/vworkapp_ruby/base/base.rb
|
102
|
+
- lib/vworkapp_ruby/base/httparty_monkey_patch.rb
|
103
|
+
- lib/vworkapp_ruby/base/resource.rb
|
104
|
+
- lib/vworkapp_ruby/base/response_error.rb
|
105
|
+
- lib/vworkapp_ruby/contact.rb
|
106
|
+
- lib/vworkapp_ruby/custom_field.rb
|
81
107
|
- lib/vworkapp_ruby/customer.rb
|
82
|
-
- lib/vworkapp_ruby/httparty_monkey_patch.rb
|
83
108
|
- lib/vworkapp_ruby/job.rb
|
84
109
|
- lib/vworkapp_ruby/location.rb
|
85
|
-
- lib/vworkapp_ruby/
|
110
|
+
- lib/vworkapp_ruby/step.rb
|
111
|
+
- lib/vworkapp_ruby/telemetry.rb
|
86
112
|
- lib/vworkapp_ruby/worker.rb
|
113
|
+
- spec/base_spec.rb
|
87
114
|
- spec/customer_spec.rb
|
88
115
|
- spec/job_spec.rb
|
116
|
+
- spec/resource_spec.rb
|
117
|
+
- spec/support/active_model_lint.rb
|
89
118
|
- spec/worker_spec.rb
|
119
|
+
- vworkapp_ruby-0.1.0.gem
|
90
120
|
- vworkapp_ruby.gemspec
|
91
|
-
homepage: http://
|
121
|
+
homepage: http://developer.vworkapp.com
|
92
122
|
licenses: []
|
93
123
|
|
94
124
|
post_install_message:
|
@@ -122,6 +152,6 @@ rubyforge_project:
|
|
122
152
|
rubygems_version: 1.8.11
|
123
153
|
signing_key:
|
124
154
|
specification_version: 3
|
125
|
-
summary:
|
155
|
+
summary: A ruby wrapper for vWorkApp's API
|
126
156
|
test_files: []
|
127
157
|
|
data/examples/create_job.rb
DELETED
@@ -1,34 +0,0 @@
|
|
1
|
-
# -------------
|
2
|
-
# Example: Create job
|
3
|
-
# -------------
|
4
|
-
# Imports a list of jobs from Google Docs and creates them in vWorkApp
|
5
|
-
#
|
6
|
-
|
7
|
-
$LOAD_PATH.unshift(File.dirname(__FILE__) + '/../lib') unless $LOAD_PATH.include?(File.dirname(__FILE__) + '/../lib')
|
8
|
-
require "rubygems"
|
9
|
-
require "vworkapp_ruby"
|
10
|
-
|
11
|
-
MIN = 60
|
12
|
-
HOUR = 60 * MIN
|
13
|
-
|
14
|
-
VWorkApp.api_key = "AtuogECLCV2R7uT-fkPg"
|
15
|
-
|
16
|
-
puts <<-EOL
|
17
|
-
----------------------------
|
18
|
-
vWorkApp - Create Job
|
19
|
-
----------------------------
|
20
|
-
EOL
|
21
|
-
|
22
|
-
job = VWorkApp::Job.new(
|
23
|
-
"ACME Inc.",
|
24
|
-
"Standard Booking",
|
25
|
-
10 * HOUR,
|
26
|
-
[
|
27
|
-
VWorkApp::Step.new("End", VWorkApp::Location.from_address("201 1st Street, SF", :us)),
|
28
|
-
VWorkApp::Step.new("Start", VWorkApp::Location.new("880 Harrison St!", 37.779536, -122.401503))
|
29
|
-
],
|
30
|
-
[
|
31
|
-
VWorkApp::CustomField.new("Note", "Hi There!"),
|
32
|
-
]
|
33
|
-
)
|
34
|
-
puts "Created Job, id is: #{job.create.id}"
|
data/examples/print_jobs.rb
DELETED
@@ -1,31 +0,0 @@
|
|
1
|
-
# -------------
|
2
|
-
# Example: Print Jobs
|
3
|
-
# -------------
|
4
|
-
# Gets all workers, and then prints a list of each's unstarted jobs to the terminal.
|
5
|
-
#
|
6
|
-
|
7
|
-
$LOAD_PATH.unshift(File.dirname(__FILE__) + '/../lib') unless $LOAD_PATH.include?(File.dirname(__FILE__) + '/../lib')
|
8
|
-
require "rubygems"
|
9
|
-
require "vworkapp_ruby"
|
10
|
-
|
11
|
-
VWorkApp.api_key = "AtuogECLCV2R7uT-fkPg"
|
12
|
-
|
13
|
-
# MultiXml.parser = :rexml
|
14
|
-
# p MultiXml.parser
|
15
|
-
|
16
|
-
puts <<-EOL
|
17
|
-
----------------------------
|
18
|
-
vWorkApp - List of jobs
|
19
|
-
----------------------------
|
20
|
-
EOL
|
21
|
-
workers = VWorkApp::Worker.all
|
22
|
-
|
23
|
-
workers.each do |worker|
|
24
|
-
puts "Worker: #{worker.id}-#{worker.name}"
|
25
|
-
jobs = VWorkApp::Job.find(:worker_id => worker.id, :state => "not_started")
|
26
|
-
jobs.each do |job|
|
27
|
-
puts "\t #{job.third_party_id || job.id}, #{job.customer_name}, #{job.template_name}"
|
28
|
-
# p job
|
29
|
-
end
|
30
|
-
puts ""
|
31
|
-
end
|
data/lib/vworkapp_ruby/base.rb
DELETED
@@ -1,72 +0,0 @@
|
|
1
|
-
require 'httparty'
|
2
|
-
require 'active_support/core_ext/hash'
|
3
|
-
|
4
|
-
module VWorkApp
|
5
|
-
|
6
|
-
class << self
|
7
|
-
@api_key = "YOU NEED TO SPECIFY YOUR API KEY!!"
|
8
|
-
|
9
|
-
def api_key=(key)
|
10
|
-
@api_key = key
|
11
|
-
end
|
12
|
-
|
13
|
-
def api_key
|
14
|
-
@api_key
|
15
|
-
end
|
16
|
-
|
17
|
-
end
|
18
|
-
|
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
|
27
|
-
|
28
|
-
class Base
|
29
|
-
include HTTParty
|
30
|
-
include AttributeEquality
|
31
|
-
|
32
|
-
base_uri 'api.vworkapp.com/api/2.0'
|
33
|
-
# http_proxy 'localhost', 8888
|
34
|
-
|
35
|
-
headers({
|
36
|
-
"Content-Type" => "text/xml",
|
37
|
-
"User-Agent" => "Ruby.vWorkApp.API"
|
38
|
-
})
|
39
|
-
|
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)
|
59
|
-
end
|
60
|
-
end
|
61
|
-
|
62
|
-
def perform(action, url, query = {}, body = nil, &block)
|
63
|
-
self.class.perform(action, url, query, body, &block)
|
64
|
-
end
|
65
|
-
|
66
|
-
def self.bad_response(response)
|
67
|
-
raise "#{response.code} - #{response.msg}: #{response.body}"
|
68
|
-
end
|
69
|
-
|
70
|
-
end
|
71
|
-
|
72
|
-
end
|
@@ -1,35 +0,0 @@
|
|
1
|
-
module VWorkApp
|
2
|
-
|
3
|
-
# Error raised on a bad response
|
4
|
-
class ResponseError < StandardError
|
5
|
-
|
6
|
-
attr_reader :response, :code, :errors
|
7
|
-
|
8
|
-
def initialize(res)
|
9
|
-
@response = res.response
|
10
|
-
@code = res.code
|
11
|
-
@errors = parse_errors(res.parsed_response)
|
12
|
-
end
|
13
|
-
|
14
|
-
def to_s
|
15
|
-
p @response.body
|
16
|
-
"#{code.to_s} #{response.msg}".strip
|
17
|
-
end
|
18
|
-
|
19
|
-
private
|
20
|
-
|
21
|
-
def parse_errors(errors)
|
22
|
-
return case errors
|
23
|
-
when Hash
|
24
|
-
errors.collect{|k,v| "#{k}: #{v}"}
|
25
|
-
when String
|
26
|
-
[errors]
|
27
|
-
when Array
|
28
|
-
errors
|
29
|
-
else []
|
30
|
-
end
|
31
|
-
end
|
32
|
-
|
33
|
-
end
|
34
|
-
|
35
|
-
end
|