lws 0.1.5 → 0.1.6

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/auth.rb CHANGED
@@ -37,6 +37,18 @@ module LWS::Auth
37
37
  #@!attribute avatar_url
38
38
  # @return [String] the avatar URL of the account
39
39
 
40
+ #@!attribute apps
41
+ # @return [Array<App>] the apps that are assigned to the account
42
+ has_many :apps
43
+
44
+ #@!attribute devices
45
+ # @return [Array<Device>] the devices that are assigned to the account
46
+ has_many :devices
47
+
48
+ #@!attribute users
49
+ # @return [Array<User>] the users that are assigned to the account
50
+ has_many :users
51
+
40
52
  #@!attribute company
41
53
  # @return [Company] the company that the account belongs to
42
54
  belongs_to :company
@@ -101,6 +113,14 @@ module LWS::Auth
101
113
  #@!attribute id [r]
102
114
  # @return [Fixnum] the (unique) ID of the company
103
115
 
116
+ #@!attribute apps
117
+ # @return [Array<App>] the apps that are assigned to the company
118
+ has_many :apps
119
+
120
+ #@!attribute accounts
121
+ # @return [Array<Account>] the accounts that are assigned to the company
122
+ has_many :accounts
123
+
104
124
  #@!attribute address
105
125
  # @return [String] the address of the company
106
126
 
@@ -194,14 +214,24 @@ module LWS::Auth
194
214
  #@!attribute user_agent
195
215
  # @return [String] the user agent/browser string when the token was used
196
216
 
217
+ #@!attribute account
218
+ # @return [Account] the account the token belongs to (through either
219
+ # the user or the device)
220
+ belongs_to :account
221
+
222
+ #@!attribute account_id
223
+ # @return [Fixnum] the ID of the account the token belongs to
224
+
197
225
  #@!attribute user
198
- # @return [Account] the (user) account the token belongs to
199
- belongs_to :user, class_name: "Account"
226
+ # @note Each token is associated to either a user or a device.
227
+ # @return [User] the user the token belongs to
228
+ belongs_to :user
200
229
 
201
230
  #@!attribute user_id
202
- # @return [Fixnum] the ID of the (user) account the token belongs to
231
+ # @return [Fixnum] the ID of the user the token belongs to
203
232
 
204
233
  #@!attribute device
234
+ # @note Each token is associated to either a user or a device.
205
235
  # @return [Device] the device the token belongs to
206
236
  belongs_to :device
207
237
 
@@ -222,4 +252,35 @@ module LWS::Auth
222
252
  end
223
253
  end
224
254
 
255
+ # = The user class
256
+ class User < LWS::Generic::Model
257
+ use_api LWS::Auth.api
258
+
259
+ #@!attribute id [r]
260
+ # @return [Fixnum] the (unique) ID of the user
261
+
262
+ #@!attribute email
263
+ # @return [String] the email address of the user
264
+
265
+ #@!attribute password_digest
266
+ # @return [String] the digested version of the password of the user
267
+
268
+ #@!attribute account
269
+ # @return [Account] the account that the user belongs to
270
+ belongs_to :account
271
+
272
+ #@!attribute account_id
273
+ # @return [Fixnum] the ID of the account that the user belongs to
274
+
275
+ #@!attribute created_at
276
+ # @return [String] the timestamp of when the user was created
277
+
278
+ #@!attribute updated_at
279
+ # @return [String] the timestamp of when the user was last updated
280
+
281
+ def initialize(attrs = {})
282
+ super
283
+ end
284
+ end
285
+
225
286
  end
data/lib/lws/version.rb CHANGED
@@ -2,6 +2,6 @@ module LWS
2
2
 
3
3
  # The LWS library version.
4
4
  # @note This is not the API version!
5
- VERSION = '0.1.5'
5
+ VERSION = '0.1.6'
6
6
 
7
7
  end
data/lib/lws.rb CHANGED
@@ -70,13 +70,16 @@ module LWS
70
70
  mattr_reader :config
71
71
 
72
72
  # = The API configuration class
73
+ #
74
+ # @note Either the API token or API token middleware needs to be
75
+ # configured for LWS to work properly!
73
76
  class Config < Hashie::Dash
74
77
  #@!attribute api_token
75
78
  # @return [String, nil] the API token necessary to gain access
76
79
  property :api_token
77
80
 
78
81
  #@!attribute api_token_middleware
79
- # @return [Fardaday::Middleware, nil] the API token middleware that
82
+ # @return [Faraday::Middleware, nil] the API token middleware that
80
83
  # provides the API token to the request at runtime
81
84
  property :api_token_middleware
82
85
 
@@ -21,41 +21,27 @@ end
21
21
  class TestAPITokenMiddleware < MiniTest::Unit::TestCase
22
22
 
23
23
  def test_working_token_authenticator
24
- LWS.setup do |config|
25
- config.api_token = nil
26
- config.api_token_middleware = WorkingTokenAuthenticator
27
- if ENV["LC_LWS_TEST_DEBUG"].present?
28
- config.http_debug = true
29
- config.json_debug = true
30
- end
31
- config.environment = :development
32
- end
24
+ # Configure the working token authenticator instead of the test API token
25
+ reconfigure(api_token: nil,
26
+ api_token_middleware: WorkingTokenAuthenticator)
33
27
 
34
28
  task = LWS::Auth::Task.all.first
35
29
  refute_nil(task)
36
30
 
37
31
  # Restore the token
38
- LWS.config.api_token = ENV["LC_LWS_TEST_TOKEN"]
39
- LWS.config.api_token_middleware = nil
32
+ reconfigure
40
33
  end
41
34
 
42
35
  def test_broken_token_authenticator
43
- LWS.setup do |config|
44
- config.api_token = nil
45
- config.api_token_middleware = BrokenTokenAuthenticator
46
- if ENV["LC_LWS_TEST_DEBUG"].present?
47
- config.http_debug = true
48
- config.json_debug = true
49
- end
50
- config.environment = :development
51
- end
36
+ # Configure the working token authenticator instead of the test API token
37
+ reconfigure(api_token: nil,
38
+ api_token_middleware: BrokenTokenAuthenticator)
52
39
 
53
40
  task = LWS::Auth::Task.all.first
54
41
  assert_nil(task)
55
42
 
56
43
  # Restore the token
57
- LWS.config.api_token = ENV["LC_LWS_TEST_TOKEN"]
58
- LWS.config.api_token_middleware = nil
44
+ reconfigure
59
45
  end
60
46
 
61
47
  end
data/test/test_auth.rb CHANGED
@@ -15,7 +15,14 @@ class TestAuthAccount < MiniTest::Unit::TestCase
15
15
  end
16
16
 
17
17
  def test_valid_account_associations
18
+ assert_instance_of(App, @account.apps.first)
18
19
  assert_instance_of(Company, @account.company)
20
+ if @account.users.present?
21
+ assert_instance_of(User, @account.users.first)
22
+ end
23
+ if @account.devices.present?
24
+ assert_instance_of(Device, @account.devices.first)
25
+ end
19
26
  end
20
27
 
21
28
  end
@@ -51,7 +58,9 @@ class TestAuthCompany < MiniTest::Unit::TestCase
51
58
  end
52
59
 
53
60
  def test_valid_company_associations
61
+ assert_instance_of(Account, @company.accounts.first)
54
62
  assert_instance_of(Account, @company.contact_person)
63
+ assert_instance_of(App, @company.apps.first)
55
64
  end
56
65
 
57
66
  end
@@ -81,7 +90,7 @@ class TestAuthToken < MiniTest::Unit::TestCase
81
90
  include LWS::Auth
82
91
 
83
92
  def setup
84
- @token = Token.all.first
93
+ @token = Token.find(ENV["LC_LWS_TEST_TOKEN"])
85
94
  end
86
95
 
87
96
  def test_valid_token
@@ -92,13 +101,36 @@ class TestAuthToken < MiniTest::Unit::TestCase
92
101
  end
93
102
 
94
103
  def test_valid_token_associations
104
+ refute_nil(@token.account)
95
105
  if @token.user.present?
96
- assert_instance_of(Account, @token.user)
106
+ assert_instance_of(User, @token.user)
107
+ assert_equal(@token.user.account.id, @token.account.id)
97
108
  elsif @token.device.present?
98
109
  assert_instance_of(Device, @token.device)
110
+ assert_equal(@token.device.account.id, @token.account.id)
99
111
  else
100
- fail "token should be associated with either an account or a device"
112
+ fail "token should be associated with either a user or a device"
101
113
  end
102
114
  end
103
115
 
104
116
  end
117
+
118
+ class TestAuthUser < MiniTest::Unit::TestCase
119
+
120
+ include LWS::Auth
121
+
122
+ def setup
123
+ @user = User.all.first
124
+ end
125
+
126
+ def test_valid_user
127
+ refute_nil(@user)
128
+ assert_instance_of(User, @user)
129
+ refute_nil(@user.id)
130
+ end
131
+
132
+ def test_valid_user_associations
133
+ assert_instance_of(Account, @user.account)
134
+ end
135
+
136
+ end
data/test/test_helper.rb CHANGED
@@ -3,11 +3,21 @@ require "minitest/autorun"
3
3
 
4
4
  raise "Test token not set" if ENV["LC_LWS_TEST_TOKEN"].blank?
5
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
6
+ def reconfigure(options = {})
7
+ LWS.setup do |config|
8
+ config.api_token = ENV["LC_LWS_TEST_TOKEN"]
9
+ if ENV["LC_LWS_TEST_DEBUG"].present?
10
+ config.http_debug = true
11
+ config.json_debug = true
12
+ end
13
+ config.environment = :development
14
+
15
+ # Override the config with the given options.
16
+ options.each do |key, value|
17
+ config[key] = value
18
+ end
11
19
  end
12
- config.environment = :development
13
20
  end
21
+
22
+ # Perform initial configuration.
23
+ reconfigure
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: lws
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.5
4
+ version: 0.1.6
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2016-03-09 00:00:00.000000000 Z
12
+ date: 2016-03-23 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: faraday_middleware
16
- requirement: &14765880 !ruby/object:Gem::Requirement
16
+ requirement: &8912660 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -24,10 +24,10 @@ dependencies:
24
24
  version: '1.0'
25
25
  type: :runtime
26
26
  prerelease: false
27
- version_requirements: *14765880
27
+ version_requirements: *8912660
28
28
  - !ruby/object:Gem::Dependency
29
29
  name: hashie
30
- requirement: &14764980 !ruby/object:Gem::Requirement
30
+ requirement: &8911800 !ruby/object:Gem::Requirement
31
31
  none: false
32
32
  requirements:
33
33
  - - ! '>='
@@ -35,10 +35,10 @@ dependencies:
35
35
  version: '0'
36
36
  type: :runtime
37
37
  prerelease: false
38
- version_requirements: *14764980
38
+ version_requirements: *8911800
39
39
  - !ruby/object:Gem::Dependency
40
40
  name: her
41
- requirement: &14764260 !ruby/object:Gem::Requirement
41
+ requirement: &8911060 !ruby/object:Gem::Requirement
42
42
  none: false
43
43
  requirements:
44
44
  - - ~>
@@ -46,10 +46,10 @@ dependencies:
46
46
  version: 0.8.1
47
47
  type: :runtime
48
48
  prerelease: false
49
- version_requirements: *14764260
49
+ version_requirements: *8911060
50
50
  - !ruby/object:Gem::Dependency
51
51
  name: hashie
52
- requirement: &14763660 !ruby/object:Gem::Requirement
52
+ requirement: &8910480 !ruby/object:Gem::Requirement
53
53
  none: false
54
54
  requirements:
55
55
  - - ! '>='
@@ -57,10 +57,10 @@ dependencies:
57
57
  version: '0'
58
58
  type: :development
59
59
  prerelease: false
60
- version_requirements: *14763660
60
+ version_requirements: *8910480
61
61
  - !ruby/object:Gem::Dependency
62
62
  name: her
63
- requirement: &14762960 !ruby/object:Gem::Requirement
63
+ requirement: &8909760 !ruby/object:Gem::Requirement
64
64
  none: false
65
65
  requirements:
66
66
  - - ~>
@@ -68,10 +68,10 @@ dependencies:
68
68
  version: 0.8.1
69
69
  type: :development
70
70
  prerelease: false
71
- version_requirements: *14762960
71
+ version_requirements: *8909760
72
72
  - !ruby/object:Gem::Dependency
73
73
  name: minitest
74
- requirement: &14762380 !ruby/object:Gem::Requirement
74
+ requirement: &8909180 !ruby/object:Gem::Requirement
75
75
  none: false
76
76
  requirements:
77
77
  - - ! '>='
@@ -79,10 +79,10 @@ dependencies:
79
79
  version: '0'
80
80
  type: :development
81
81
  prerelease: false
82
- version_requirements: *14762380
82
+ version_requirements: *8909180
83
83
  - !ruby/object:Gem::Dependency
84
84
  name: rake
85
- requirement: &14778140 !ruby/object:Gem::Requirement
85
+ requirement: &8924920 !ruby/object:Gem::Requirement
86
86
  none: false
87
87
  requirements:
88
88
  - - ~>
@@ -90,7 +90,7 @@ dependencies:
90
90
  version: 0.9.2
91
91
  type: :development
92
92
  prerelease: false
93
- version_requirements: *14778140
93
+ version_requirements: *8924920
94
94
  description: ! "This library for Ruby provides access to the LeftClick\n web services/applications
95
95
  using a model-based structure that abstracts from API calls\n using the available
96
96
  REST interfaces."