lws 0.4.2 → 6.1.0.beta1

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/lib/lws/generic.rb CHANGED
@@ -15,65 +15,61 @@
15
15
  module LWS::Generic
16
16
 
17
17
  # = The generic model class
18
- class Model
19
- include Her::Model
20
-
18
+ #
19
+ # This model forms the base for all LWS models.
20
+ class Model < Spyke::Base
21
21
  include_root_in_json true
22
+
23
+ # @private
24
+ # @!visibility private
25
+ #
26
+ # Adds an attribute for this class.
27
+ #
28
+ # @note
29
+ # This is just a singular version helper method of the +attributes+
30
+ # method provided by Spyke.
31
+ # @param [Symbol] name the name of the attribute to add
32
+ # @return [void]
33
+ def self.attribute(name)
34
+ attributes(name)
35
+ end
36
+
37
+ # @private
38
+ # @!visibility private
39
+ #
40
+ # Sets the Faraday API object used for this class. This will used by
41
+ # Spyke.
42
+ #
43
+ # @param api The Faraday connection that makes requests to the API
44
+ # @return [Faraday] A Faraday connection that makes requests to the API
45
+ def self.use_api(api)
46
+ self.connection = api
47
+ self.include_root_in_json self.name.split("::").last.underscore.to_sym
48
+ api
49
+ end
22
50
  end
23
51
 
24
52
  # = The configuration class
25
53
  class Configuration < Model
26
- #@!attribute id [r]
27
- # @return [Fixnum] the (unique) ID of the configuration
28
-
29
- #@!attribute key
30
- # @return [String] the configuration key
31
-
32
- #@!attribute value
33
- # @return [String] the configuration value
34
-
35
- #@!attribute created_at
36
- # @return [String] the timestamp of when the configuration was created
37
-
38
- #@!attribute updated_at
39
- # @return [String] the timestamp of when the configuration was last updated
40
-
41
- self # To ensure that YARD does not skip the attributes of this class
42
- end
43
-
44
- # = The task class
45
- class Task < Model
46
- #@!attribute id [r]
47
- # @return [Fixnum] the (unique) ID of the task
48
-
49
- #@!attribute name
50
- # @return [String] the name of the task
51
-
52
- #@!attribute interval
53
- # @return [Fixnum] the interval in minutes
54
-
55
- #@!attribute function
56
- # @return [String] the function to run
57
-
58
- #@!attribute last_ran
59
- # @return [String] the time the task was last run
60
-
61
- #@!attribute started
62
- # @return [String] the time the task was started
63
-
64
- #@!attribute node_name
65
- # @return [String] the name of the node
54
+ # @!attribute id [r]
55
+ # @return [Fixnum] the (unique) ID of the configuration
56
+ attribute :id
66
57
 
67
- #@!attribute pid
68
- # @return [String] the process ID of the task
58
+ # @!attribute key
59
+ # @return [String] the configuration key
60
+ attribute :key
69
61
 
70
- #@!attribute created_at
71
- # @return [String] the timestamp of when the map was created
62
+ # @!attribute value
63
+ # @return [String] the configuration value
64
+ attribute :value
72
65
 
73
- #@!attribute updated_at
74
- # @return [String] the timestamp of when the map was last updated
66
+ # @!attribute created_at [r]
67
+ # @return [String] the timestamp of when the configuration was created
68
+ attribute :created_at
75
69
 
76
- self # To ensure that YARD does not skip the attributes of this class
70
+ # @!attribute updated_at [r]
71
+ # @return [String] the timestamp of when the configuration was last updated
72
+ attribute :updated_at
77
73
  end
78
74
 
79
75
  end
data/lib/lws/maps.rb CHANGED
@@ -20,7 +20,7 @@ module LWS::Maps
20
20
  end
21
21
  # :nocov:
22
22
 
23
- #@!visibility private
23
+ # @!visibility private
24
24
  def self.api
25
25
  LWS.setup_api(LWS.config.endpoints[:maps] ||
26
26
  ENDPOINT[LWS.config.environment])
@@ -33,72 +33,118 @@ module LWS::Maps
33
33
  use_api LWS::Maps.api
34
34
  end
35
35
 
36
- # (see Generic::Task)
37
- class Task < LWS::Generic::Task
38
- use_api LWS::Maps.api
39
- end
40
-
41
36
  ### App specific classes
42
37
 
43
38
  # = The map class
44
39
  class Map < LWS::Generic::Model
45
40
  use_api LWS::Maps.api
46
41
 
47
- #@!attribute id [r]
48
- # @return [Fixnum] the (unique) ID of the map
42
+ # @!attribute id [r]
43
+ # @return [Fixnum] the (unique) ID of the map
44
+ attribute :id
49
45
 
50
- #@!attribute company
51
- # @return [LWS::Auth::Company] the company that maintains/owns the map
46
+ # @!attribute company
47
+ # @return [LWS::Auth::Company] the company that maintains/owns the map
52
48
  belongs_to :company, class_name: "LWS::Auth::Company"
53
49
 
54
- #@!attribute company_id
55
- # @return [Fixnum] the ID of the company that maintains/owns the map
50
+ # @!attribute company_id
51
+ # @return [Fixnum] the ID of the company that maintains/owns the map
52
+ attribute :company_id
56
53
 
57
- #@!attribute markers
58
- # @return [Array<Marker>] the list of associated markers
54
+ # @!attribute markers
55
+ # @return [Array<Marker>] the list of associated markers
59
56
  has_many :markers
60
57
 
61
- #@!attribute name
62
- # @return [String] the name of the map
58
+ # @!attribute name
59
+ # @return [String] the name of the map
60
+ attribute :name
61
+
62
+ # @!attribute source
63
+ # @return [Source] the map source used for tiling the map
64
+ belongs_to :source
63
65
 
64
- #@!attribute created_at
65
- # @return [String] the timestamp of when the map was created
66
+ # @!attribute source_id
67
+ # @return [Fixnum] the ID of the map source used for tiling the map
68
+ attribute :source_id
66
69
 
67
- #@!attribute updated_at
68
- # @return [String] the timestamp of when the map was last updated
70
+ # @!attribute created_at [r]
71
+ # @return [String] the timestamp of when the map was created
72
+ attribute :created_at
73
+
74
+ # @!attribute updated_at [r]
75
+ # @return [String] the timestamp of when the map was last updated
76
+ attribute :updated_at
69
77
  end
70
78
 
71
79
  # = The map marker class
72
80
  class Marker < LWS::Generic::Model
73
81
  use_api LWS::Maps.api
74
82
 
75
- #@!attribute id [r]
76
- # @return [Fixnum] the (unique) ID of the map marker
83
+ # @!attribute id [r]
84
+ # @return [Fixnum] the (unique) ID of the map marker
85
+ attribute :id
86
+
87
+ # @attribute lat
88
+ # @return [String, nil] the latitude of the map marker
89
+ attribute :lat
90
+
91
+ # @attribute long
92
+ # @return [String, nil] the longitued of the map marker
93
+ attribute :long
77
94
 
78
- #@!attribute map
79
- # @return [Map] the map that the marker is placed on
95
+ # @!attribute map
96
+ # @return [Map] the map that the marker is placed on
80
97
  belongs_to :map
81
98
 
82
- #@!attribute map_id
83
- # @return [Fixnum] the ID of the map that the marker is placed on
99
+ # @!attribute map_id
100
+ # @return [Fixnum] the ID of the map that the marker is placed on
101
+ attribute :map_id
102
+
103
+ # @!attribute name
104
+ # @return [String] the name of the map marker
105
+ attribute :name
106
+
107
+ # @attribute website
108
+ # @return [String, nil] the website URL of the map marker
109
+ attribute :website
110
+
111
+ # @!attribute created_at [r]
112
+ # @return [String] the timestamp of when the map marker was created
113
+ attribute :created_at
114
+
115
+ # @!attribute updated_at [r]
116
+ # @return [String] the timestamp of when the map marker was last updated
117
+ attribute :updated_at
118
+ end
119
+
120
+ # = The map source class
121
+ class Source < LWS::Generic::Model
122
+ use_api LWS::Maps.api
84
123
 
85
- #@!attribute name
86
- # @return [String] the name of the map marker
124
+ # @!attribute id [r]
125
+ # @return [Fixnum] the (unique) ID of the map source
126
+ attribute :id
87
127
 
88
- #@attribute lat
89
- # @return [String] the latitude of the map marker
128
+ # @!attribute key
129
+ # @return [String] the key used by the map implementation to select the
130
+ # map source
131
+ attribute :key
90
132
 
91
- #@attribute long
92
- # @return [String] the longitued of the map marker
133
+ # @!attribute maps
134
+ # @return [Array<Map>] the maps using the map source
135
+ has_many :maps
93
136
 
94
- #@attribute website
95
- # @return [String] the website URL of the map marker
137
+ # @!attribute name
138
+ # @return [String] the name of the map source
139
+ attribute :name
96
140
 
97
- #@!attribute created_at
98
- # @return [String] the timestamp of when the map marker was created
141
+ # @!attribute created_at [r]
142
+ # @return [String] the timestamp of when the map source was created
143
+ attribute :created_at
99
144
 
100
- #@!attribute updated_at
101
- # @return [String] the timestamp of when the map marker was last updated
145
+ # @!attribute updated_at [r]
146
+ # @return [String] the timestamp of when the map source was last updated
147
+ attribute :updated_at
102
148
  end
103
149
 
104
150
  end
data/lib/lws/presence.rb CHANGED
@@ -20,7 +20,7 @@ module LWS::Presence
20
20
  end
21
21
  # :nocov:
22
22
 
23
- #@!visibility private
23
+ # @!visibility private
24
24
  def self.api
25
25
  LWS.setup_api(LWS.config.endpoints[:presence] ||
26
26
  ENDPOINT[LWS.config.environment])
@@ -33,117 +33,137 @@ module LWS::Presence
33
33
  use_api LWS::Presence.api
34
34
  end
35
35
 
36
- # (see Generic::Task)
37
- class Task < LWS::Generic::Task
38
- use_api LWS::Presence.api
39
- end
40
-
41
36
  ### App specific classes
42
37
 
43
38
  # = The location class
44
39
  class Location < LWS::Generic::Model
45
40
  use_api LWS::Presence.api
46
41
 
47
- #@!attribute id [r]
48
- # @return [Fixnum] the (unique) ID of the location
42
+ # @!attribute id [r]
43
+ # @return [Fixnum] the (unique) ID of the location
44
+ attribute :id
49
45
 
50
- #@!attribute name
51
- # @return [String] the name of the location
52
-
53
- #@!attribute lat
54
- # @return [Float] the latitude of the location
46
+ # @!attribute company
47
+ # @return [LWS::Auth::Company] the company the location belongs to
48
+ belongs_to :company, class_name: "LWS::Auth::Company"
55
49
 
56
- #@!attribute long
57
- # @return [Float] the longitude of the location
50
+ # @!attribute company_id
51
+ # @return [Fixnum] the ID of the company the location belongs to
52
+ attribute :company_id
58
53
 
59
- #@!attribute range
60
- # @return [Integer] the range around the location in meters
54
+ # @!attribute lat
55
+ # @return [Float] the latitude of the location
56
+ attribute :lat
61
57
 
62
- #@!attribute logoff_time
63
- # @return [String] the time everybody is automatically logged off
64
- # (format HH:MM)
58
+ # @!attribute logoff_time
59
+ # @return [String] the time everybody is automatically logged off
60
+ # (format HH:MM)
61
+ attribute :logoff_time
65
62
 
66
- #@!attribute company
67
- # @return [Auth::Company] the company the location belongs to
68
- belongs_to :company, class_name: "LWS::Auth::Company"
63
+ # @!attribute long
64
+ # @return [Float] the longitude of the location
65
+ attribute :long
69
66
 
70
- #@!attribute company_id
71
- # @return [Fixnum] the ID of the company the location belongs to
67
+ # @!attribute name
68
+ # @return [String] the name of the location
69
+ attribute :name
72
70
 
73
- #@!attribute people
74
- # @return [Array<Person>] the people associated with the location
71
+ # @!attribute people
72
+ # @return [Array<Person>] the people associated with the location
75
73
  has_many :people
76
74
 
77
- #@!attribute created_at
78
- # @return [String] the timestamp of when the location was created
75
+ # @!attribute range
76
+ # @return [Integer] the range around the location in meters
77
+ attribute :range
78
+
79
+ # @!attribute created_at [r]
80
+ # @return [String] the timestamp of when the location was created
81
+ attribute :created_at
79
82
 
80
- #@!attribute updated_at
81
- # @return [String] the timestamp of when the location was last updated
83
+ # @!attribute updated_at [r]
84
+ # @return [String] the timestamp of when the location was last updated
85
+ attribute :updated_at
82
86
  end
83
-
87
+
84
88
  # = The person class
85
89
  class Person < LWS::Generic::Model
86
90
  use_api LWS::Presence.api
87
91
 
88
- #@!attribute id [r]
89
- # @return [Fixnum] the (unique) ID of the person
92
+ # @!attribute id [r]
93
+ # @return [Fixnum] the (unique) ID of the person
94
+ attribute :id
90
95
 
91
- #@!attribute name
92
- # @return [String] the name of the person
96
+ # @!attribute company
97
+ # @return [LWS::Auth::Company] the company the person belongs to
98
+ belongs_to :company, class_name: "LWS::Auth::Company"
93
99
 
94
- #@!attribute udid
95
- # @return [String] the unique device ID (e.g. of a mobile phone)
96
- # linked to the person
100
+ # @!attribute company_id
101
+ # @return [Fixnum] the ID of the company the person belongs to
102
+ attribute :company_id
97
103
 
98
- #@!attribute rfid
99
- # @return [String] the RFID tag ID linked to the person
104
+ # @!attribute customer_reference
105
+ # @return [String, nil] the customer specific reference for the person
106
+ attribute :customer_reference
100
107
 
101
- #@!attribute company
102
- # @return [Auth::Company] the company the person belongs to
103
- belongs_to :company, class_name: "LWS::Auth::Company"
108
+ # @!attribute ero
109
+ # @return [Boolean] whether the person is emergency response
110
+ # certified
111
+ attribute :ero
104
112
 
105
- #@!attribute company_id
106
- # @return [Fixnum] the ID of the company the person belongs to
113
+ # @!attribute extra_info
114
+ # @return [String, nil] some extra info for the person
115
+ attribute :extra_info
107
116
 
108
- #@!attribute lat
109
- # @return [Float] the exact latitude of the person's location
117
+ # @!attribute last_sync
118
+ # @return [String, nil] the last date/time the status was updated via a
119
+ # device or RFID tag
120
+ attribute :last_sync
110
121
 
111
- #@!attribute long
112
- # @return [Float] the exact longitude of the person's location
122
+ # @!attribute lat
123
+ # @return [Float, nil] the exact latitude of the person's location
124
+ attribute :lat
113
125
 
114
- #@!attribute status
115
- # @return ["available", "busy", "away", "disabled"] the presence status
116
- # of the person
126
+ # @!attribute long
127
+ # @return [Float, nil] the exact longitude of the person's location
128
+ attribute :long
117
129
 
118
- #@!attribute location
119
- # @return [Location] the location the person is located at
130
+ # @!attribute location
131
+ # @return [Location] the location the person is located at
120
132
  belongs_to :location
121
133
 
122
- #@!attribute location_id
123
- # @return [Fixnum] the ID of the location the person is located at
134
+ # @!attribute location_id
135
+ # @return [Fixnum] the ID of the location the person is located at
136
+ attribute :location_id
124
137
 
125
- #@!attribute extra_info
126
- # @return [String] some extra info for the person
138
+ # @!attribute name
139
+ # @return [String] the name of the person
140
+ attribute :name
127
141
 
128
- #@!attribute customer_reference
129
- # @return [String] customer specific reference for the person
142
+ # @!attribute picture_url
143
+ # @return [String, nil] the URL of the picture of the person
144
+ attribute :picture_url
130
145
 
131
- #@!attribute ero
132
- # @return [Boolean] flag whether the person is emergency response
133
- # certified
146
+ # @!attribute rfid
147
+ # @return [String, nil] the RFID tag ID linked to the person
148
+ attribute :rfid
134
149
 
135
- #@!attribute picture_url
136
- # @return [String] an URL of the picture of the person
150
+ # @!attribute status
151
+ # @return ["available", "busy", "away", "disabled", nil]
152
+ # the presence status of the person
153
+ attribute :status
137
154
 
138
- #@!attribute last_sync
139
- # @return [String] last time the status was updated via a device or
140
- # RFID tag
155
+ # @!attribute udid
156
+ # @return [String, nil] the unique device ID (e.g. of a mobile phone)
157
+ # linked to the person
158
+ attribute :udid
141
159
 
142
- #@!attribute created_at
143
- # @return [String] the timestamp of when the person was created
160
+ # @!attribute created_at [r]
161
+ # @return [String] the timestamp of when the person was created
162
+ attribute :created_at
144
163
 
145
- #@!attribute updated_at
146
- # @return [String] the timestamp of when the person was last updated
164
+ # @!attribute updated_at [r]
165
+ # @return [String] the timestamp of when the person was last updated
166
+ attribute :updated_at
147
167
  end
148
168
 
149
169
  end
data/lib/lws/stubbing.rb CHANGED
@@ -96,8 +96,8 @@ module LWS
96
96
  {}
97
97
  end
98
98
  raise "fixture #{fixture_name} not found (app: #{app_name}, URI: #{path})" unless fixture
99
- app_endpoint_url = LWS.app_module(app_name).api.options[:url]
100
- app_endpoint_uri = URI.parse(app_endpoint_url)
99
+ app_module = LWS.app_module(app_name)
100
+ app_endpoint_uri = app_module.api.url_prefix.dup
101
101
  app_endpoint_uri.path = path
102
102
  full_uri = "%s://%s:%s%s" % [app_endpoint_uri.scheme,
103
103
  app_endpoint_uri.host,