work_surfer 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: bb41f0781d7dc4c27cd0c65f693cfcb9cc95e6f1
4
+ data.tar.gz: 4acd6534f45640819f9c4b6913a2c107be46d3d0
5
+ SHA512:
6
+ metadata.gz: be9c3cb2c02a6aa5dac5c660c41f893d15d67b6ab850162ebb35d50be6e9f2c374be3a7a03dfe4725ba00aa0527db07c479b55fffb685f17347c3ab61694c0b7
7
+ data.tar.gz: 2dc3e10684f9286d44760a9c786b2bddf16e4f2b8640c180cddcf328819fb0824190d8465237d7a89895477a38d71d0e7f7c77b7f7815f59875e0ec4e26ba30a
@@ -0,0 +1,7 @@
1
+ # frozen_string_literal: true
2
+
3
+ module WorkSurfer
4
+ end
5
+
6
+ require "work_surfer/api"
7
+ require "work_surfer/client"
@@ -0,0 +1,15 @@
1
+ # frozen_string_literal: true
2
+
3
+ module WorkSurfer
4
+ module API
5
+ class << self
6
+ def client
7
+ Client.default_client
8
+ end
9
+ end
10
+ end
11
+ end
12
+
13
+ require "work_surfer/api/approved_plans"
14
+ require "work_surfer/api/territories"
15
+ require "work_surfer/api/time_of_arrival"
@@ -0,0 +1,17 @@
1
+ # frozen_string_literal: true
2
+
3
+ module WorkSurfer
4
+ module API
5
+ class ApprovedPlans
6
+ class << self
7
+ def get(route_id, territory_id: WorkSurfer::Client.default_territory_id)
8
+ API.client.get("territories/#{territory_id}/approved/routes/#{route_id}")
9
+ end
10
+
11
+ def list(date: "today", territory_id: WorkSurfer::Client.default_territory_id)
12
+ API.client.get("territories/#{territory_id}/approved/routes?date=#{date}")
13
+ end
14
+ end
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,13 @@
1
+ # frozen_string_literal: true
2
+
3
+ module WorkSurfer
4
+ module API
5
+ class Territories
6
+ class << self
7
+ def list
8
+ API.client.get("territories")
9
+ end
10
+ end
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,21 @@
1
+ # frozen_string_literal: true
2
+
3
+ module WorkSurfer
4
+ module API
5
+ class TimeOfArrival
6
+ class << self
7
+ def get(route_id, territory_id: WorkSurfer::Client.default_territory_id)
8
+ API.client.get("territories/#{territory_id}/toa/routes/#{route_id}")
9
+ end
10
+
11
+ def list(date: nil, territory_id: WorkSurfer::Client.default_territory_id, vehicle_id: nil)
12
+ API.client.get("territories/#{territory_id}/toa/routes", { params: {
13
+ date: date,
14
+ territory_id: territory_id,
15
+ vehicle: vehicle_id,
16
+ }.reject { |k, v| v.nil? } })
17
+ end
18
+ end
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,87 @@
1
+ # frozen_string_literal: true
2
+
3
+ module WorkSurfer
4
+ class Client
5
+ OPTIONS_WITH_CLASS_DEFAULT = [
6
+ :api_key,
7
+ :connection_builder,
8
+ :connection_options,
9
+ :default_headers,
10
+ :default_territory_id,
11
+ :url_base,
12
+ ].freeze
13
+
14
+ OPTIONS_WITH_CLASS_DEFAULT.each do |option|
15
+ cattr_accessor option
16
+ attr_accessor option
17
+ end
18
+
19
+ self.connection_builder = ->(builder) {
20
+ builder.adapter Faraday.default_adapter
21
+ builder.request :url_encoded
22
+ builder.response :parse_json
23
+ }
24
+
25
+ self.connection_options = {}
26
+ self.default_headers = {
27
+ "X-WorkWave-Key": proc { api_key },
28
+ }
29
+ self.url_base = "https://wwrm.workwave.com/api/v1/"
30
+
31
+ [
32
+ :delete,
33
+ :get,
34
+ :post,
35
+ :put,
36
+ ].each do |http_verb|
37
+ define_method(http_verb) do |*args|
38
+ connection.public_send(http_verb, *args)
39
+ end
40
+ end
41
+
42
+ def initialize(**options)
43
+ unknown_options = options.keys - OPTIONS_WITH_CLASS_DEFAULT
44
+ raise ArgumentError, "Unknown option key(s): #{unknown_options.join(", ")}. Valid options are: #{OPTIONS_WITH_CLASS_DEFAULT.join(", ")}." if unknown_options.any?
45
+
46
+ OPTIONS_WITH_CLASS_DEFAULT.each do |option|
47
+ value = options[option].nil? ? self.class.public_send(option) : options[option]
48
+ public_send("#{option}=", value)
49
+ end
50
+
51
+ self
52
+ end
53
+
54
+ protected
55
+
56
+ def connection
57
+ @connection ||= Faraday::Connection.new(
58
+ url_base,
59
+ connection_options.merge(
60
+ headers: evaluate_hash_values(default_headers)
61
+ ),
62
+ &connection_builder
63
+ )
64
+ end
65
+
66
+ def evaluate_hash_values(hash)
67
+ Hash[
68
+ *hash.collect do |k, v|
69
+ [
70
+ k,
71
+ v.is_a?(Proc) ? instance_eval(&v) : v,
72
+ ]
73
+ end.flatten
74
+ ]
75
+ end
76
+
77
+ class << self
78
+ def default_client
79
+ @default_client ||= new
80
+ end
81
+
82
+ def default_client=(client)
83
+ @default_client = client
84
+ end
85
+ end
86
+ end
87
+ end
metadata ADDED
@@ -0,0 +1,85 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: work_surfer
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Niels Ganser
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2016-10-23 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: faraday
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: 0.9.0
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: 0.9.0
27
+ - !ruby/object:Gem::Dependency
28
+ name: faraday_middleware
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0.9'
34
+ - - "<="
35
+ - !ruby/object:Gem::Version
36
+ version: '0.10'
37
+ type: :runtime
38
+ prerelease: false
39
+ version_requirements: !ruby/object:Gem::Requirement
40
+ requirements:
41
+ - - ">="
42
+ - !ruby/object:Gem::Version
43
+ version: '0.9'
44
+ - - "<="
45
+ - !ruby/object:Gem::Version
46
+ version: '0.10'
47
+ description:
48
+ email: niels@herimedia.com
49
+ executables: []
50
+ extensions: []
51
+ extra_rdoc_files: []
52
+ files:
53
+ - lib/work_surfer.rb
54
+ - lib/work_surfer/api.rb
55
+ - lib/work_surfer/api/approved_plans.rb
56
+ - lib/work_surfer/api/territories.rb
57
+ - lib/work_surfer/api/time_of_arrival.rb
58
+ - lib/work_surfer/client.rb
59
+ homepage: https://github.com/herimedia/work_surfer
60
+ licenses:
61
+ - Apache-2.0
62
+ metadata: {}
63
+ post_install_message:
64
+ rdoc_options: []
65
+ require_paths:
66
+ - lib
67
+ required_ruby_version: !ruby/object:Gem::Requirement
68
+ requirements:
69
+ - - ">="
70
+ - !ruby/object:Gem::Version
71
+ version: '0'
72
+ required_rubygems_version: !ruby/object:Gem::Requirement
73
+ requirements:
74
+ - - ">="
75
+ - !ruby/object:Gem::Version
76
+ version: '0'
77
+ requirements: []
78
+ rubyforge_project:
79
+ rubygems_version: 2.5.1
80
+ signing_key:
81
+ specification_version: 4
82
+ summary: An experiemental unofficial API client for the WorkWave.com Route Manager
83
+ API.
84
+ test_files: []
85
+ has_rdoc: