work_surfer 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: bb41f0781d7dc4c27cd0c65f693cfcb9cc95e6f1
4
- data.tar.gz: 4acd6534f45640819f9c4b6913a2c107be46d3d0
3
+ metadata.gz: c456764defdde3b3827c67ae0666f72a8a500780
4
+ data.tar.gz: 35e2173c4f097597631d3a9b86636a419d6eba7c
5
5
  SHA512:
6
- metadata.gz: be9c3cb2c02a6aa5dac5c660c41f893d15d67b6ab850162ebb35d50be6e9f2c374be3a7a03dfe4725ba00aa0527db07c479b55fffb685f17347c3ab61694c0b7
7
- data.tar.gz: 2dc3e10684f9286d44760a9c786b2bddf16e4f2b8640c180cddcf328819fb0824190d8465237d7a89895477a38d71d0e7f7c77b7f7815f59875e0ec4e26ba30a
6
+ metadata.gz: c1eb2b9e3cbaf0a72e8545871ff30c295112023ee8b83f2f1adb910a5df4815be2bf557ecaab204fb0f6b64472e63b55376a4bc647c78bfad9c3b57089fa5332
7
+ data.tar.gz: d201a387bdbb4eff926f96d84c831e415d74656be2de4bdba7d1c6238c9f2e4d295d1b88cc1728c1424439856dcb14476b6a5da4e7fd90378b95025aa01fafcf
@@ -2,14 +2,14 @@
2
2
 
3
3
  module WorkSurfer
4
4
  module API
5
- class ApprovedPlans
5
+ class ApprovedPlans < Base
6
6
  class << self
7
7
  def get(route_id, territory_id: WorkSurfer::Client.default_territory_id)
8
- API.client.get("territories/#{territory_id}/approved/routes/#{route_id}")
8
+ client.get("territories/#{territory_id}/approved/routes/#{route_id}")
9
9
  end
10
10
 
11
11
  def list(date: "today", territory_id: WorkSurfer::Client.default_territory_id)
12
- API.client.get("territories/#{territory_id}/approved/routes?date=#{date}")
12
+ client.get("territories/#{territory_id}/approved/routes?date=#{formatted_date(date)}")
13
13
  end
14
14
  end
15
15
  end
@@ -0,0 +1,29 @@
1
+ # frozen_string_literal: true
2
+
3
+ module WorkSurfer
4
+ module API
5
+ class Base
6
+ class << self
7
+ protected
8
+
9
+ def client
10
+ Client.default_client
11
+ end
12
+
13
+ def formatted_date(date = nil)
14
+ return date if date.to_s == "today"
15
+ return nil if date.to_s.strip.length <= 0
16
+
17
+ date = date.respond_to?(:to_date)
18
+ if date.respond_to?(:to_date)
19
+ date.to_date
20
+ else
21
+ Date.parse(date.to_s)
22
+ end
23
+
24
+ date.strftime("%Y%m%d")
25
+ end
26
+ end
27
+ end
28
+ end
29
+ end
@@ -2,10 +2,10 @@
2
2
 
3
3
  module WorkSurfer
4
4
  module API
5
- class Territories
5
+ class Territories < Base
6
6
  class << self
7
7
  def list
8
- API.client.get("territories")
8
+ client.get("territories")
9
9
  end
10
10
  end
11
11
  end
@@ -2,15 +2,15 @@
2
2
 
3
3
  module WorkSurfer
4
4
  module API
5
- class TimeOfArrival
5
+ class TimeOfArrival < Base
6
6
  class << self
7
7
  def get(route_id, territory_id: WorkSurfer::Client.default_territory_id)
8
- API.client.get("territories/#{territory_id}/toa/routes/#{route_id}")
8
+ client.get("territories/#{territory_id}/toa/routes/#{route_id}")
9
9
  end
10
10
 
11
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,
12
+ client.get("territories/#{territory_id}/toa/routes", { params: {
13
+ date: formatted_date(date),
14
14
  territory_id: territory_id,
15
15
  vehicle: vehicle_id,
16
16
  }.reject { |k, v| v.nil? } })
@@ -2,14 +2,11 @@
2
2
 
3
3
  module WorkSurfer
4
4
  module API
5
- class << self
6
- def client
7
- Client.default_client
8
- end
9
- end
10
5
  end
11
6
  end
12
7
 
8
+ require "work_surfer/api/base"
9
+
13
10
  require "work_surfer/api/approved_plans"
14
11
  require "work_surfer/api/territories"
15
12
  require "work_surfer/api/time_of_arrival"
@@ -12,14 +12,27 @@ module WorkSurfer
12
12
  ].freeze
13
13
 
14
14
  OPTIONS_WITH_CLASS_DEFAULT.each do |option|
15
- cattr_accessor option
16
- attr_accessor option
15
+ define_singleton_method(option) do
16
+ instance_variable_get("@#{option}")
17
+ end
18
+
19
+ define_singleton_method("#{option}=") do |*args|
20
+ instance_variable_set("@#{option}", *args)
21
+ end
22
+
23
+ define_method(option) do
24
+ instance_variable_get("@#{option}")
25
+ end
26
+
27
+ define_method("#{option}=") do |*args|
28
+ instance_variable_set("@#{option}", *args)
29
+ end
17
30
  end
18
31
 
19
32
  self.connection_builder = ->(builder) {
20
33
  builder.adapter Faraday.default_adapter
21
34
  builder.request :url_encoded
22
- builder.response :parse_json
35
+ builder.response :json
23
36
  }
24
37
 
25
38
  self.connection_options = {}
data/lib/work_surfer.rb CHANGED
@@ -1,5 +1,8 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require "faraday"
4
+ require "faraday_middleware"
5
+
3
6
  module WorkSurfer
4
7
  end
5
8
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: work_surfer
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Niels Ganser
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-10-23 00:00:00.000000000 Z
11
+ date: 2016-10-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: faraday
@@ -53,6 +53,7 @@ files:
53
53
  - lib/work_surfer.rb
54
54
  - lib/work_surfer/api.rb
55
55
  - lib/work_surfer/api/approved_plans.rb
56
+ - lib/work_surfer/api/base.rb
56
57
  - lib/work_surfer/api/territories.rb
57
58
  - lib/work_surfer/api/time_of_arrival.rb
58
59
  - lib/work_surfer/client.rb