lws 0.1.1

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,12 @@
1
+ # RubyMine IDE
2
+ /.idea/
3
+
4
+ # Ignore YARD stuff
5
+ .yardoc
6
+ doc/
7
+
8
+ # Ignore gem stuff
9
+ *.gem
10
+ .bundle
11
+ Gemfile.lock
12
+ pkg/*
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source "http://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in lws.gemspec
4
+ gemspec
data/Rakefile ADDED
@@ -0,0 +1,18 @@
1
+ # Rakefile with tasks for the LeftClick web services
2
+
3
+ require 'bundler/gem_tasks'
4
+ require "rake/testtask"
5
+ require "yard"
6
+
7
+ Rake::TestTask.new do |t|
8
+ t.libs << "test" << "lib"
9
+ t.pattern = "test/test_*.rb"
10
+ end
11
+
12
+ YARD::Rake::YardocTask.new do |t|
13
+ t.files = ["lib"]
14
+ t.options = ["--no-private",
15
+ "--title", "LeftClick Web Services Documentation"]
16
+ end
17
+
18
+ task default: :test
data/bin/lwsconsole ADDED
@@ -0,0 +1,64 @@
1
+ #!/usr/bin/ruby
2
+ #
3
+ # lwsconsole - A command-line tool to access the LWS web services
4
+ #
5
+ # Usage: lwsconsole <LWS API token> [<app>:<endpoint> ...]
6
+
7
+ require "irb"
8
+ require "lws"
9
+ require "pp"
10
+
11
+ # Module to allow for start an interfactive session at any point
12
+ # in a Ruby program.
13
+ # Source: http://jasonroelofs.com/2009/04/02/embedding-irb-into-your-ruby-application/
14
+ module IRB
15
+ def self.start_session(binding)
16
+ unless @__initialized
17
+ args = ARGV
18
+ ARGV.replace(ARGV.dup)
19
+ IRB.setup(nil)
20
+ ARGV.replace(args)
21
+ @__initialized = true
22
+ end
23
+
24
+ workspace = WorkSpace.new(binding)
25
+
26
+ irb = Irb.new(workspace)
27
+
28
+ @CONF[:IRB_RC].call(irb.context) if @CONF[:IRB_RC]
29
+ @CONF[:MAIN_CONTEXT] = irb.context
30
+
31
+ catch(:IRB_EXIT) do
32
+ irb.eval_input
33
+ end
34
+ end
35
+ end
36
+
37
+ # Parse the command-line arguments
38
+ if ARGV.length < 1
39
+ puts "Usage: #{$0} <LWS API token> [<app>:<endpoint> ...]"
40
+ exit 1
41
+ end
42
+ api_token = ARGV.shift
43
+ endpoints = {}
44
+ ARGV.each do |app_endpoint|
45
+ app,endpoint = app_endpoint.split(':', 2)
46
+ endpoints[app.to_sym] = endpoint
47
+ end
48
+
49
+ # Set up the API
50
+ LWS.setup do |config|
51
+ config.api_token = api_token
52
+ config.http_debug = true
53
+ config.json_debug = true
54
+ config.endpoints = endpoints
55
+ end
56
+
57
+ def reload!
58
+ LWS.load_app_modules
59
+ end
60
+
61
+ # Use the LWS module as default namespace
62
+ include LWS
63
+
64
+ IRB.start_session(binding)
data/lib/lws.rb ADDED
@@ -0,0 +1,149 @@
1
+ require "hashie"
2
+ require "her"
3
+ require "pp"
4
+
5
+ # = Main LeftClick web services module
6
+ #
7
+ # This module is the main namespace for the web service/application
8
+ # libraries that are represented by submodules. The {LWS} module is used
9
+ # to load, set up and configure the supported application/web service
10
+ # libraries.
11
+ module LWS
12
+
13
+ # The list of supported apps (web service libraries) loaded by
14
+ # {.setup}.
15
+ SUPPORTED_APPS = [:generic, :auth, :maps, :presence]
16
+
17
+ # The LWS library version.
18
+ # @note This is not the API version!
19
+ VERSION = '0.1.1'
20
+
21
+ # @!visibility private
22
+ class HTTPLogger < Faraday::Response::Middleware
23
+
24
+ def call(env)
25
+ puts ">>> #{env[:method].upcase} #{env[:url].to_s}"
26
+ env[:request_headers].each do |hdr, val|
27
+ puts " #{hdr}: #{val}"
28
+ end
29
+ puts ">>> #{env[:body] || "nil"}"
30
+ super
31
+ end
32
+
33
+ def on_complete(env)
34
+ super
35
+ puts "<<< HTTP #{env[:status].to_s}"
36
+ env[:response_headers].each do |hdr, val|
37
+ puts " #{hdr}: #{val}"
38
+ end
39
+ puts "<<< #{env[:body] || "nil"}"
40
+ end
41
+
42
+ end
43
+
44
+ # @!visibility private
45
+ class JSONLogger < Faraday::Response::Middleware
46
+
47
+ def on_complete(env)
48
+ dump = MultiJson.dump(env[:body], pretty: true)
49
+ dump.split("\n").each { |line| puts "||| #{line}" }
50
+ end
51
+
52
+ end
53
+
54
+ # @!visibility private
55
+ class RequestHeaders < Faraday::Middleware
56
+
57
+ def initialize(app, token)
58
+ super(app)
59
+ @token = token
60
+ end
61
+
62
+ def call(env)
63
+ env[:request_headers]["X-Token"] = @token
64
+ env[:request_headers]["Accept"] = "application/json"
65
+ @app.call(env)
66
+ end
67
+
68
+ end
69
+
70
+ # @return [Config] the API configuration for the web services
71
+ mattr_reader :config
72
+
73
+ # = The API configuration class
74
+ class Config < Hashie::Dash
75
+ #@!attribute api_token
76
+ # @return [String] the API token necessary to gain access
77
+ property :api_token
78
+
79
+ #@!attribute endpoints
80
+ # @return [Hash{Symbol=>String}] a mapping of application endpoint
81
+ # overrides
82
+ property :endpoints, default: {}
83
+
84
+ #@!attribute http_debug
85
+ # @return [Boolean] whether to show HTTP debug messages
86
+ property :http_debug, default: false
87
+
88
+ #@!attribute json_debug
89
+ # @return [Boolean] whether to show JSON debug messages
90
+ property :json_debug, default: false
91
+ end
92
+
93
+ # Sets up the application API libraries using the provided
94
+ # configuration (see {Config}).
95
+ #
96
+ # @example Set up LWS with a token, an endpoint override and HTTP debugging
97
+ # LWS.setup do |config|
98
+ # config.api_token = "MY_TOKEN"
99
+ # config.endpoints = { maps: https://maps-dev.leftclick.eu }
100
+ # config.http_debug = true
101
+ # end
102
+ #
103
+ # @yieldparam [Config] config an API configuration object that can be
104
+ # configured
105
+ # @raise if API token is not configured
106
+ # @return [LWS] the module itself
107
+ def self.setup(&block)
108
+ @@config = Config.new
109
+ yield @@config
110
+
111
+ raise "API token is required" if config.api_token.blank?
112
+
113
+ load_app_modules
114
+
115
+ return self
116
+ end
117
+
118
+ # @!visibility private
119
+ def self.setup_api(api_url)
120
+ api = Her::API.new
121
+ api.setup(url: api_url) do |c|
122
+ # Request
123
+ c.use RequestHeaders, config.api_token
124
+ c.use Faraday::Request::UrlEncoded
125
+
126
+ # Response
127
+ c.use JSONLogger if config.json_debug
128
+ c.use Her::Middleware::DefaultParseJSON
129
+ c.use HTTPLogger if config.http_debug
130
+
131
+ # Adapter
132
+ c.use Faraday::Adapter::NetHttp
133
+ end
134
+
135
+ return api
136
+ end
137
+
138
+ # (Re)loads the app modules (usually done by {.setup}).
139
+ #
140
+ # @return [Array<Symbol>] the apps that were loaded
141
+ # (see also {SUPPORTED_APPS})
142
+ def self.load_app_modules
143
+ app_module_path = File.dirname(__FILE__)
144
+ SUPPORTED_APPS.each do |app|
145
+ load "#{app_module_path}/lws/#{app}.rb"
146
+ end
147
+ end
148
+
149
+ end # module LWS
data/lib/lws/auth.rb ADDED
@@ -0,0 +1,219 @@
1
+ # = The auth app module
2
+ module LWS::Auth
3
+
4
+ # The API endpoint for the auth app
5
+ ENDPOINT = "https://auth.leftclick.eu/" unless defined? ENDPOINT
6
+
7
+ # @!visibility private
8
+ def self.api
9
+ @@api ||= LWS.setup_api(LWS.config.endpoints[:auth] || ENDPOINT)
10
+ end
11
+
12
+ ### Generic classes
13
+
14
+ class Configuration < LWS::Generic::Configuration
15
+ use_api LWS::Auth.api
16
+ end
17
+
18
+ class Task < LWS::Generic::Task
19
+ use_api LWS::Auth.api
20
+ end
21
+
22
+ ### App specific classes
23
+
24
+ # = The account class
25
+ class Account < LWS::Generic::Model
26
+ use_api LWS::Auth.api
27
+
28
+ #@!attribute id [r]
29
+ # @return [Fixnum] the (unique) ID of the account
30
+
31
+ #@!attribute avatar_url
32
+ # @return [String] the avatar URL of the account
33
+
34
+ #@!attribute company
35
+ # @return [Company] the company that the account belongs to
36
+ belongs_to :company
37
+
38
+ #@!attribute company_id
39
+ # @return [Fixnum] the ID of the company that the account belongs to
40
+
41
+ #@!attribute language
42
+ # @return [String] the language of the account
43
+
44
+ #@!attribute name
45
+ # @return [String] the name of the account
46
+
47
+ #@!attribute created_at
48
+ # @return [String] the timestamp of when the account was created
49
+
50
+ #@!attribute updated_at
51
+ # @return [String] the timestamp of when the account was last updated
52
+
53
+ def initialize(attrs = {})
54
+ super
55
+ end
56
+ end
57
+
58
+ # = The app class
59
+ class App < LWS::Generic::Model
60
+ use_api LWS::Auth.api
61
+
62
+ #@!attribute id [r]
63
+ # @return [Fixnum] the (unique) ID of the account
64
+
65
+ #@!attribute name
66
+ # @return [String] the name of the app
67
+
68
+ #@!attribute app_key
69
+ # @return [String] the internal key used for the app
70
+
71
+ #@!attribute url
72
+ # @return [String] the web location of the app
73
+
74
+ #@!attribute secret
75
+ # @return [String] the shared secred used for logging in to the app
76
+
77
+ #@!attribute icon
78
+ # @return [String] the icon ID/name of the app
79
+
80
+ #@!attribute created_at
81
+ # @return [String] the timestamp of when the app was created
82
+
83
+ #@!attribute updated_at
84
+ # @return [String] the timestamp of when the app was last updated
85
+
86
+ def initialize(attrs = {})
87
+ super
88
+ end
89
+ end
90
+
91
+ # = The company class
92
+ class Company < LWS::Generic::Model
93
+ use_api LWS::Auth.api
94
+
95
+ #@!attribute id [r]
96
+ # @return [Fixnum] the (unique) ID of the company
97
+
98
+ #@!attribute address
99
+ # @return [String] the address of the company
100
+
101
+ #@!attribute city
102
+ # @return [String] the city of the company
103
+
104
+ #@!attribute contact_person
105
+ # @return [Account] the contact person of the company
106
+ belongs_to :contact_person, class_name: "Account"
107
+
108
+ #@!attribute contact_person_id
109
+ # @return [Fixnum] the ID of the contact person of the company
110
+
111
+ #@!attribute country
112
+ # @return [String] the country of the company
113
+
114
+ #@!attribute name
115
+ # @return [String] the name of the company
116
+
117
+ #@!attribute number
118
+ # @return [String] the street address number of the company
119
+
120
+ #@!attribute parent
121
+ # @return [Company] the parenty company
122
+ belongs_to :parent, class_name: "Company"
123
+
124
+ #@!attribute parent_id
125
+ # @return [Fixnum] the ID of the parenty company
126
+
127
+ #@!attribute zip_code
128
+ # @return [String] the zip code of the company
129
+
130
+ #@!attribute created_at
131
+ # @return [String] the timestamp of when the company was created
132
+
133
+ #@!attribute updated_at
134
+ # @return [String] the timestamp of when the company was last updated
135
+
136
+ def initialize(attrs = {})
137
+ super
138
+ end
139
+ end
140
+
141
+ # = The device class
142
+ class Device < LWS::Generic::Model
143
+ use_api LWS::Auth.api
144
+
145
+ #@!attribute id [r]
146
+ # @return [Fixnum] the (unique) ID of the device
147
+
148
+ #@!attribute name
149
+ # @return [String] the name of the device
150
+
151
+ #@!attribute account
152
+ # @return [Account] the account that the device belongs to
153
+ belongs_to :account
154
+
155
+ #@!attribute account_id
156
+ # @return [Fixnum] the ID of the account that the device belongs to
157
+
158
+ #@!attribute created_at
159
+ # @return [String] the timestamp of when the device was created
160
+
161
+ #@!attribute updated_at
162
+ # @return [String] the timestamp of when the device was last updated
163
+
164
+ def initialize(attrs = {})
165
+ super
166
+ end
167
+ end
168
+
169
+ # = The token class
170
+ class Token < LWS::Generic::Model
171
+ use_api LWS::Auth.api
172
+
173
+ #@!attribute id [r]
174
+ # @return [Fixnum] the (unique) ID of the token
175
+
176
+ #@!attribute name
177
+ # @return [String] the name of the token
178
+
179
+ #@!attribute token
180
+ # @return [String] the actual token string
181
+
182
+ #@!attribute used_on
183
+ # @return [String] the timestamp the token was last used
184
+
185
+ #@!attribute ip_address
186
+ # @return [String] the location/IP address the token is used on
187
+
188
+ #@!attribute user_agent
189
+ # @return [String] the user agent/browser string when the token was used
190
+
191
+ #@!attribute user
192
+ # @return [Account] the (user) account the token belongs to
193
+ belongs_to :user, class_name: "Account"
194
+
195
+ #@!attribute user_id
196
+ # @return [Fixnum] the ID of the (user) account the token belongs to
197
+
198
+ #@!attribute device
199
+ # @return [Device] the device the token belongs to
200
+ belongs_to :device
201
+
202
+ #@!attribute device_id
203
+ # @return [Fixnum] the ID of the device the token belongs to
204
+
205
+ #@!attribute expires_on
206
+ # @return [String] the timestamp the token will (or has) expire(d)
207
+
208
+ #@!attribute created_at
209
+ # @return [String] the timestamp of when the token was created
210
+
211
+ #@!attribute updated_at
212
+ # @return [String] the timestamp of when the token was last updated
213
+
214
+ def initialize(attrs = {})
215
+ super
216
+ end
217
+ end
218
+
219
+ end
@@ -0,0 +1,72 @@
1
+ # = The generic app module
2
+ #
3
+ # This module contains classes that are present in all applications.
4
+ module LWS::Generic
5
+
6
+ # = The generic model class
7
+ class Model
8
+ include Her::Model
9
+
10
+ include_root_in_json true
11
+ end
12
+
13
+ # = The configuration class
14
+ class Configuration < Model
15
+ #@!attribute id [r]
16
+ # @return [Fixnum] the (unique) ID of the configuration
17
+
18
+ #@!attribute key
19
+ # @return [String] the configuration key
20
+
21
+ #@!attribute value
22
+ # @return [String] the configuration value
23
+
24
+ #@!attribute created_at
25
+ # @return [String] the timestamp of when the configuration was created
26
+
27
+ #@!attribute updated_at
28
+ # @return [String] the timestamp of when the configuration was last updated
29
+
30
+ def initialize(attrs = {})
31
+ super
32
+ end
33
+ end
34
+
35
+ # = The task class
36
+ class Task < Model
37
+ #@!attribute id [r]
38
+ # @return [Fixnum] the (unique) ID of the task
39
+
40
+ #@!attribute name
41
+ # @return [String] the name of the task
42
+
43
+ #@!attribute interval
44
+ # @return [Fixnum] the interval in minutes
45
+
46
+ #@!attribute function
47
+ # @return [String] the function to run
48
+
49
+ #@!attribute last_ran
50
+ # @return [String] the time the task was last run
51
+
52
+ #@!attribute started
53
+ # @return [String] the time the task was started
54
+
55
+ #@!attribute node_name
56
+ # @return [String] the name of the node
57
+
58
+ #@!attribute pid
59
+ # @return [String] the process ID of the task
60
+
61
+ #@!attribute created_at
62
+ # @return [String] the timestamp of when the map was created
63
+
64
+ #@!attribute updated_at
65
+ # @return [String] the timestamp of when the map was last updated
66
+
67
+ def initialize(attrs = {})
68
+ super
69
+ end
70
+ end
71
+
72
+ end
data/lib/lws/maps.rb ADDED
@@ -0,0 +1,93 @@
1
+ # = The maps app module
2
+ module LWS::Maps
3
+
4
+ # The API endpoint for the map app
5
+ ENDPOINT = "https://maps.leftclick.eu/" unless defined? ENDPOINT
6
+
7
+ #@!visibility private
8
+ def self.api
9
+ @@api ||= LWS.setup_api(LWS.config.endpoints[:maps] || ENDPOINT)
10
+ end
11
+
12
+ ### Generic classes
13
+
14
+ class Configuration < LWS::Generic::Configuration
15
+ use_api LWS::Maps.api
16
+ end
17
+
18
+ class Task < LWS::Generic::Task
19
+ use_api LWS::Maps.api
20
+ end
21
+
22
+ ### App specific classes
23
+
24
+ # = The map class
25
+ class Map < LWS::Generic::Model
26
+ use_api LWS::Maps.api
27
+
28
+ #@!attribute id [r]
29
+ # @return [Fixnum] the (unique) ID of the map
30
+
31
+ #@!attribute company
32
+ # @return [LWS::Auth::Company] the company that maintains/owns the map
33
+ belongs_to :company, class_name: "LWS::Auth::Company"
34
+
35
+ #@!attribute company_id
36
+ # @return [Fixnum] the ID of the company that maintains/owns the map
37
+
38
+ #@!attribute markers
39
+ # @return [Array<Marker>] the list of associated markers
40
+ has_many :markers
41
+
42
+ #@!attribute name
43
+ # @return [String] the name of the map
44
+
45
+ #@!attribute created_at
46
+ # @return [String] the timestamp of when the map was created
47
+
48
+ #@!attribute updated_at
49
+ # @return [String] the timestamp of when the map was last updated
50
+
51
+ def initialize(attrs = {})
52
+ super
53
+ end
54
+ end
55
+
56
+ # = The map marker class
57
+ class Marker < LWS::Generic::Model
58
+ use_api LWS::Maps.api
59
+
60
+ #@!attribute id [r]
61
+ # @return [Fixnum] the (unique) ID of the map marker
62
+
63
+ #@!attribute map
64
+ # @return [Map] the map that the marker is placed on
65
+ belongs_to :map
66
+
67
+ #@!attribute map_id
68
+ # @return [Fixnum] the ID of the map that the marker is placed on
69
+
70
+ #@!attribute name
71
+ # @return [String] the name of the map marker
72
+
73
+ #@attribute lat
74
+ # @return [String] the latitude of the map marker
75
+
76
+ #@attribute long
77
+ # @return [String] the longitued of the map marker
78
+
79
+ #@attribute website
80
+ # @return [String] the website URL of the map marker
81
+
82
+ #@!attribute created_at
83
+ # @return [String] the timestamp of when the map marker was created
84
+
85
+ #@!attribute updated_at
86
+ # @return [String] the timestamp of when the map marker was last updated
87
+
88
+ def initialize(attrs={})
89
+ super
90
+ end
91
+ end
92
+
93
+ end
@@ -0,0 +1,134 @@
1
+ # = The presence app module
2
+ module LWS::Presence
3
+
4
+ # The API endpoint for the presence app
5
+ ENDPOINT = "https://presence.leftclick.eu/" unless defined? ENDPOINT
6
+
7
+ #@!visibility private
8
+ def self.api
9
+ @@api ||= LWS.setup_api(LWS.config.endpoints[:presence] || ENDPOINT)
10
+ end
11
+
12
+ ### Generic classes
13
+
14
+ class Configuration < LWS::Generic::Configuration
15
+ use_api LWS::Presence.api
16
+ end
17
+
18
+ class Task < LWS::Generic::Task
19
+ use_api LWS::Presence.api
20
+ end
21
+
22
+ ### App specific classes
23
+
24
+ # = The location class
25
+ class Location < LWS::Generic::Model
26
+ use_api LWS::Presence.api
27
+
28
+ #@!attribute id [r]
29
+ # @return [Fixnum] the (unique) ID of the location
30
+
31
+ #@!attribute name
32
+ # @return [String] the name of the location
33
+
34
+ #@!attribute lat
35
+ # @return [Float] the latitude of the location
36
+
37
+ #@!attribute long
38
+ # @return [Float] the longitude of the location
39
+
40
+ #@!attribute range
41
+ # @return [Integer] the range around the location in meters
42
+
43
+ #@!attribute logoff_time
44
+ # @return [String] the time everybody is automatically logged off
45
+ # (format HH:MM)
46
+
47
+ #@!attribute company
48
+ # @return [Auth::Company] the company the location belongs to
49
+ belongs_to :company, class_name: "LWS::Auth::Company"
50
+
51
+ #@!attribute company_id
52
+ # @return [Fixnum] the ID of the company the location belongs to
53
+
54
+ #@!attribute people
55
+ # @return [Array<Person>] the people associated with the location
56
+ has_many :people
57
+
58
+ #@!attribute created_at
59
+ # @return [String] the timestamp of when the location was created
60
+
61
+ #@!attribute updated_at
62
+ # @return [String] the timestamp of when the location was last updated
63
+
64
+ def initialize(attrs = {})
65
+ super
66
+ end
67
+ end
68
+
69
+ class Person < LWS::Generic::Model
70
+ use_api LWS::Presence.api
71
+
72
+ #@!attribute id [r]
73
+ # @return [Fixnum] the (unique) ID of the person
74
+
75
+ #@!attribute name
76
+ # @return [String] the name of the person
77
+
78
+ #@!attribute udid
79
+ # @return [String] the unique device ID (e.g. of a mobile phone)
80
+ # linked to the person
81
+
82
+ #@!attribute rfid
83
+ # @return [String] the RFID tag ID linked to the person
84
+
85
+ #@!attribute company
86
+ # @return [Auth::Company] the company the person belongs to
87
+ belongs_to :company, class_name: "LWS::Auth::Company"
88
+
89
+ #@!attribute company_id
90
+ # @return [Fixnum] the ID of the company the person belongs to
91
+
92
+ #@!attribute lat
93
+ # @return [Float] the exact latitude of the person's location
94
+
95
+ #@!attribute long
96
+ # @return [Float] the exact longitude of the person's location
97
+
98
+ #@!attribute status
99
+ # @return ["available", "busy", "away", "disabled"] the presence status
100
+ # of the person
101
+
102
+ #@!attribute location
103
+ # @return [Location] the location the person is located at
104
+ belongs_to :location
105
+
106
+ #@!attribute location_id
107
+ # @return [Fixnum] the ID of the location the person is located at
108
+
109
+ #@!attribute extra_info
110
+ # @return [String] some extra info for the person
111
+
112
+ #@!attribute customer_reference
113
+ # @return [String] customer specific reference for the person
114
+
115
+ #@!attribute ero
116
+ # @return [Boolean] flag whether the person is emergency response
117
+ # certified
118
+
119
+ #@!attribute picture_url
120
+ # @return [String] an URL of the picture of the person
121
+
122
+ #@!attribute last_sync
123
+ # @return [String] last time the status was updated via a device or
124
+ # RFID tag
125
+
126
+ #@!attribute created_at
127
+ # @return [String] the timestamp of when the person was created
128
+
129
+ #@!attribute updated_at
130
+ # @return [String] the timestamp of when the person was last updated
131
+
132
+ end
133
+
134
+ end
data/lws.gemspec ADDED
@@ -0,0 +1,28 @@
1
+ # encoding: utf-8
2
+ $:.push File.expand_path("lib", __FILE__)
3
+ require "lws"
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = "lws"
7
+ s.version = LWS::VERSION
8
+ s.authors = ["LeftClick B.V."]
9
+ s.email = ["gem@leftclick.eu"]
10
+ s.homepage = "https://leftclick.eu/"
11
+ s.summary = "LeftClick web services library for Ruby"
12
+ s.description = %q{This library for Ruby provides access to the LeftClick
13
+ web services/applications using a model-based structure that abstracts from API calls
14
+ using the available REST interfaces.}
15
+
16
+ s.add_runtime_dependency 'hashie'
17
+ s.add_runtime_dependency 'her', '~> 0.8.1'
18
+
19
+ s.add_development_dependency 'hashie'
20
+ s.add_development_dependency 'her', '~> 0.8.1'
21
+ s.add_development_dependency 'minitest'
22
+ s.add_development_dependency 'rake', '~> 0.9.2'
23
+
24
+ s.files = `git ls-files`.split("\n")
25
+ s.test_files = `git ls-files -- test/*`.split("\n")
26
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
27
+ s.require_paths = ["lib"]
28
+ end
data/test/test_auth.rb ADDED
@@ -0,0 +1,104 @@
1
+ require "test_helper"
2
+
3
+ class TestAuthAccount < MiniTest::Unit::TestCase
4
+
5
+ include LWS::Auth
6
+
7
+ def setup
8
+ @account = Account.all.first
9
+ end
10
+
11
+ def test_valid_account
12
+ refute_nil(@account)
13
+ assert_instance_of(Account, @account)
14
+ refute_nil(@account.id)
15
+ end
16
+
17
+ def test_valid_account_associations
18
+ assert_instance_of(Company, @account.company)
19
+ end
20
+
21
+ end
22
+
23
+ class TestAuthApp < MiniTest::Unit::TestCase
24
+
25
+ include LWS::Auth
26
+
27
+ def setup
28
+ @app = App.all.first
29
+ end
30
+
31
+ def test_valid_app
32
+ refute_nil(@app)
33
+ assert_instance_of(App, @app)
34
+ refute_nil(@app.id)
35
+ end
36
+
37
+ end
38
+
39
+ class TestAuthCompany < MiniTest::Unit::TestCase
40
+
41
+ include LWS::Auth
42
+
43
+ def setup
44
+ @company = Company.all.last
45
+ end
46
+
47
+ def test_valid_company
48
+ refute_nil(@company)
49
+ assert_instance_of(Company, @company)
50
+ refute_nil(@company.id)
51
+ end
52
+
53
+ def test_valid_company_associations
54
+ assert_instance_of(Account, @company.contact_person)
55
+ end
56
+
57
+ end
58
+
59
+ class TestAuthDevice < MiniTest::Unit::TestCase
60
+
61
+ include LWS::Auth
62
+
63
+ def setup
64
+ @device = Device.all.first
65
+ end
66
+
67
+ def test_valid_device
68
+ refute_nil(@device)
69
+ assert_instance_of(Device, @device)
70
+ refute_nil(@device.id)
71
+ end
72
+
73
+ def test_valid_device_associations
74
+ assert_instance_of(Account, @device.account)
75
+ end
76
+
77
+ end
78
+
79
+ class TestAuthToken < MiniTest::Unit::TestCase
80
+
81
+ include LWS::Auth
82
+
83
+ def setup
84
+ @token = Token.all.first
85
+ end
86
+
87
+ def test_valid_token
88
+ refute_nil(@token)
89
+ assert_instance_of(Token, @token)
90
+ refute_nil(@token.id)
91
+ assert_equal(@token.token, LWS.config.api_token)
92
+ end
93
+
94
+ def test_valid_token_associations
95
+ if @token.user.present?
96
+ assert_instance_of(Account, @token.user)
97
+ elsif @token.device.present?
98
+ assert_instance_of(Device, @token.device)
99
+ else
100
+ fail "token should be associated with either an account or a device"
101
+ end
102
+ end
103
+
104
+ end
@@ -0,0 +1,35 @@
1
+ require "test_helper"
2
+
3
+ class TestGenericConfiguration < MiniTest::Unit::TestCase
4
+
5
+ # Generic class needs to be accessed under some kind of app
6
+ include LWS::Auth
7
+
8
+ def setup
9
+ @configuration = Configuration.all.first
10
+ end
11
+
12
+ def test_valid_configuration
13
+ refute_nil(@configuration)
14
+ assert_instance_of(Configuration, @configuration)
15
+ refute_nil(@configuration.id)
16
+ end
17
+
18
+ end
19
+
20
+ class TestGenericTask < MiniTest::Unit::TestCase
21
+
22
+ # Generic class needs to be accessed under some kind of app
23
+ include LWS::Auth
24
+
25
+ def setup
26
+ @task = Task.all.first
27
+ end
28
+
29
+ def test_valid_task
30
+ refute_nil(@task)
31
+ assert_instance_of(Task, @task)
32
+ refute_nil(@task.id)
33
+ end
34
+
35
+ end
@@ -0,0 +1,15 @@
1
+ require "lws"
2
+ require "minitest/autorun"
3
+
4
+ raise "Test token not set" if ENV["LC_LWS_TEST_TOKEN"].blank?
5
+
6
+ LWS.setup do |config|
7
+ config.api_token = ENV["LC_LWS_TEST_TOKEN"]
8
+ if ENV["LC_LWS_TEST_DEBUG"].present?
9
+ config.http_debug = true
10
+ config.json_debug = true
11
+ end
12
+ config.endpoints = { auth: "https://auth-dev.leftclick.eu",
13
+ maps: "https://maps-dev.leftclick.eu",
14
+ presence: "https://presence-dev.leftclick.eu" }
15
+ end
data/test/test_maps.rb ADDED
@@ -0,0 +1,45 @@
1
+ require "test_helper"
2
+
3
+ class TestMapsMap < MiniTest::Unit::TestCase
4
+
5
+ include LWS::Maps
6
+
7
+ def setup
8
+ @map = Map.all.first
9
+ end
10
+
11
+ def test_valid_map
12
+ refute_nil(@map)
13
+ assert_instance_of(Map, @map)
14
+ refute_nil(@map.id)
15
+ end
16
+
17
+ def test_valid_map_associations
18
+ assert_instance_of(LWS::Auth::Company, @map.company)
19
+ assert_instance_of(Marker, @map.markers.first)
20
+ end
21
+
22
+ end
23
+
24
+ class TestMapsMap < MiniTest::Unit::TestCase
25
+
26
+ include LWS::Maps
27
+
28
+ def setup
29
+ @map = Map.all.first
30
+ # Markers only exist as child objects of maps
31
+ @marker = @map.markers.first
32
+ end
33
+
34
+ def test_valid_map
35
+ refute_nil(@map)
36
+ assert_instance_of(Map, @map)
37
+ refute_nil(@map.id)
38
+ end
39
+
40
+ def test_valid_map_associations
41
+ assert_instance_of(Map, @marker.map)
42
+ assert_equal(@marker.map, @map)
43
+ end
44
+
45
+ end
@@ -0,0 +1,43 @@
1
+ require "test_helper"
2
+
3
+ class TestPresencePerson < MiniTest::Unit::TestCase
4
+
5
+ include LWS::Presence
6
+
7
+ def setup
8
+ @person = Person.all.first
9
+ end
10
+
11
+ def test_valid_person
12
+ refute_nil(@person)
13
+ assert_instance_of(Person, @person)
14
+ refute_nil(@person.id)
15
+ end
16
+
17
+ def test_valid_person_associations
18
+ assert_instance_of(LWS::Auth::Company, @person.company)
19
+ assert_instance_of(Location, @person.location)
20
+ end
21
+
22
+ end
23
+
24
+ class TestPresenceLocation < MiniTest::Unit::TestCase
25
+
26
+ include LWS::Presence
27
+
28
+ def setup
29
+ @location = Location.all.first
30
+ end
31
+
32
+ def test_valid_location
33
+ refute_nil(@location)
34
+ assert_instance_of(Location, @location)
35
+ refute_nil(@location.id)
36
+ end
37
+
38
+ def test_valid_location_associations
39
+ assert_instance_of(LWS::Auth::Company, @location.company)
40
+ assert_instance_of(Person, @location.people.first)
41
+ end
42
+
43
+ end
metadata ADDED
@@ -0,0 +1,135 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: lws
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - LeftClick B.V.
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2016-02-15 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: hashie
16
+ requirement: &15275000 !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: *15275000
25
+ - !ruby/object:Gem::Dependency
26
+ name: her
27
+ requirement: &15274240 !ruby/object:Gem::Requirement
28
+ none: false
29
+ requirements:
30
+ - - ~>
31
+ - !ruby/object:Gem::Version
32
+ version: 0.8.1
33
+ type: :runtime
34
+ prerelease: false
35
+ version_requirements: *15274240
36
+ - !ruby/object:Gem::Dependency
37
+ name: hashie
38
+ requirement: &15273720 !ruby/object:Gem::Requirement
39
+ none: false
40
+ requirements:
41
+ - - ! '>='
42
+ - !ruby/object:Gem::Version
43
+ version: '0'
44
+ type: :development
45
+ prerelease: false
46
+ version_requirements: *15273720
47
+ - !ruby/object:Gem::Dependency
48
+ name: her
49
+ requirement: &15273060 !ruby/object:Gem::Requirement
50
+ none: false
51
+ requirements:
52
+ - - ~>
53
+ - !ruby/object:Gem::Version
54
+ version: 0.8.1
55
+ type: :development
56
+ prerelease: false
57
+ version_requirements: *15273060
58
+ - !ruby/object:Gem::Dependency
59
+ name: minitest
60
+ requirement: &15272520 !ruby/object:Gem::Requirement
61
+ none: false
62
+ requirements:
63
+ - - ! '>='
64
+ - !ruby/object:Gem::Version
65
+ version: '0'
66
+ type: :development
67
+ prerelease: false
68
+ version_requirements: *15272520
69
+ - !ruby/object:Gem::Dependency
70
+ name: rake
71
+ requirement: &15271840 !ruby/object:Gem::Requirement
72
+ none: false
73
+ requirements:
74
+ - - ~>
75
+ - !ruby/object:Gem::Version
76
+ version: 0.9.2
77
+ type: :development
78
+ prerelease: false
79
+ version_requirements: *15271840
80
+ description: ! "This library for Ruby provides access to the LeftClick\n web services/applications
81
+ using a model-based structure that abstracts from API calls\n using the available
82
+ REST interfaces."
83
+ email:
84
+ - gem@leftclick.eu
85
+ executables:
86
+ - lwsconsole
87
+ extensions: []
88
+ extra_rdoc_files: []
89
+ files:
90
+ - .gitignore
91
+ - Gemfile
92
+ - Rakefile
93
+ - bin/lwsconsole
94
+ - lib/lws.rb
95
+ - lib/lws/auth.rb
96
+ - lib/lws/generic.rb
97
+ - lib/lws/maps.rb
98
+ - lib/lws/presence.rb
99
+ - lws.gemspec
100
+ - test/test_auth.rb
101
+ - test/test_generic.rb
102
+ - test/test_helper.rb
103
+ - test/test_maps.rb
104
+ - test/test_presence.rb
105
+ homepage: https://leftclick.eu/
106
+ licenses: []
107
+ post_install_message:
108
+ rdoc_options: []
109
+ require_paths:
110
+ - lib
111
+ required_ruby_version: !ruby/object:Gem::Requirement
112
+ none: false
113
+ requirements:
114
+ - - ! '>='
115
+ - !ruby/object:Gem::Version
116
+ version: '0'
117
+ required_rubygems_version: !ruby/object:Gem::Requirement
118
+ none: false
119
+ requirements:
120
+ - - ! '>='
121
+ - !ruby/object:Gem::Version
122
+ version: '0'
123
+ requirements: []
124
+ rubyforge_project:
125
+ rubygems_version: 1.8.11
126
+ signing_key:
127
+ specification_version: 3
128
+ summary: LeftClick web services library for Ruby
129
+ test_files:
130
+ - test/test_auth.rb
131
+ - test/test_generic.rb
132
+ - test/test_helper.rb
133
+ - test/test_maps.rb
134
+ - test/test_presence.rb
135
+ has_rdoc: