flexipass 0.1.2 → 0.1.4

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
  SHA256:
3
- metadata.gz: d8d5e87b63951ed59179a0bcba33c5ce4dd98fe5882a1eb0922c6ee41133fc63
4
- data.tar.gz: b6f86a1cd68c8d8341fab16131a3cb43f08f4d5fc8e00f78d035d3b2e35052a3
3
+ metadata.gz: 30a77fddc6cce4ad68a97f565d5cab887d90f4fc177e295546d899b910c11894
4
+ data.tar.gz: b8111112a54163738e08b5dbb927dedd568ddf974ae00e131d29bd9c94eb5496
5
5
  SHA512:
6
- metadata.gz: 2318a9dcec69e5d8fa49c9dc4b2883ccc2bfdc2d776de7f0e7370bbed0bdde9cb5d177f588c8bd55c238a5a9de4d1689c719638c1fd6f8f2f673b452bd12c7f0
7
- data.tar.gz: ed2fc467ffd649d6d56dadad0caad2a9c6081a160f5101772700960c597a83728fc06b9018bbad58793f4d21e577b23d81a042ee65298206376640f452e3b4f4
6
+ metadata.gz: dc429547a93dffc3105af485abe852085a5def8cee5e84b4773689fc3b8420cb8312fbdb0063eceb2b2b6ad604c10d2dac200e86242fbbf1288e25845cd8cfc6
7
+ data.tar.gz: 79b30e43449408be529566eb63f8a18cca99d3896d29e6afcee695bd6587607d2fda94fa06586844103b7bf0fbad845035d833335e507f466ba568623c291898
@@ -2,6 +2,7 @@ require 'faraday'
2
2
  require 'base64'
3
3
 
4
4
  module Flexipass
5
+ # The Client class is responsible for making API requests to the Flexipass server.
5
6
  class Client
6
7
  def initialize
7
8
  Flexipass.configuration.validate!
@@ -19,18 +20,28 @@ module Flexipass
19
20
  end
20
21
  end
21
22
 
23
+ # Returns an instance of the MobileKey class.
22
24
  def mobile_key
23
25
  @mobile_key ||= MobileKey.new(self)
24
26
  end
25
27
 
28
+ # Returns an instance of the Door class.
26
29
  def door
27
30
  @door ||= Door.new(self)
28
31
  end
29
32
 
33
+ # Returns an instance of the Company class.
30
34
  def company
31
35
  @company ||= Company.new(self)
32
36
  end
33
37
 
38
+ # Sends a request to the Flexipass server.
39
+ #
40
+ # @param method [String] The HTTP method for the request.
41
+ # @param endpoint [String] The API endpoint.
42
+ # @param params [Hash] The request parameters.
43
+ # @return [Hash] The parsed JSON response from the server.
44
+ # @raise [ApiError] If the API request fails.
34
45
  def send_request(method, endpoint, params = {})
35
46
  response = @conn.send(method.downcase) do |req|
36
47
  req.url endpoint
@@ -43,12 +54,21 @@ module Flexipass
43
54
 
44
55
  private
45
56
 
57
+ # Generates the basic authentication header.
58
+ #
59
+ # @return [String] The basic authentication header.
46
60
  def basic_auth_header
47
61
  credentials = "#{Flexipass.configuration.username}:#{Flexipass.configuration.password}"
48
62
  encoded_credentials = Base64.strict_encode64(credentials)
49
63
  "Basic #{encoded_credentials}"
50
64
  end
51
65
 
66
+ # Handles the API response.
67
+ #
68
+ # @param response [Faraday::Response] The API response.
69
+ # @return [Hash] The parsed JSON response if the response status is between 200 and 299.
70
+ # @return [String] The response body if the JSON parsing fails.
71
+ # @raise [ApiError] If the response status is not between 200 and 299.
52
72
  def handle_response(response)
53
73
  case response.status
54
74
  when 200..299
@@ -1,13 +1,23 @@
1
1
  module Flexipass
2
+ # Represents a company in the Flexipass system.
2
3
  class Company
4
+ # Initializes a new instance of the Company class.
5
+ #
6
+ # @param client [Object] The client object used to communicate with the Flexipass API.
3
7
  def initialize(client)
4
8
  @client = client
5
9
  end
6
10
 
11
+ # Retrieves the details of the company.
12
+ #
13
+ # @return [Hash] The company details.
7
14
  def details
8
15
  @client.send_request('GET', '/Flexipass/rest/webapi/getCompanyDetails')
9
16
  end
10
17
 
18
+ # Retrieves the permissions list for the company.
19
+ #
20
+ # @return [Array] The list of permissions.
11
21
  def permissions
12
22
  @client.send_request('GET', '/Flexipass/rest/webapi/getPermissionList')
13
23
  end
@@ -1,6 +1,7 @@
1
1
  # lib/flexipass/configuration.rb
2
2
 
3
3
  module Flexipass
4
+ # The `Flexipass` module provides configuration options for the Flexipass gem.
4
5
  class Configuration
5
6
  attr_accessor :username, :password, :company_token, :environment, :enable_logging
6
7
  attr_reader :server_address
@@ -18,6 +19,8 @@ module Flexipass
18
19
  set_server_address
19
20
  end
20
21
 
22
+ # Validates the configuration options.
23
+ # Raises a `ConfigurationError` if any required options are missing or if the environment is invalid.
21
24
  def validate!
22
25
  raise ConfigurationError, 'Username must be set' if @username.nil?
23
26
  raise ConfigurationError, 'Password must be set' if @password.nil?
@@ -34,9 +37,8 @@ module Flexipass
34
37
  PROD_SERVER
35
38
  end
36
39
  end
37
-
38
-
39
40
  end
40
41
 
42
+ # Custom error class for configuration-related errors.
41
43
  class ConfigurationError < StandardError; end
42
44
  end
@@ -1,9 +1,16 @@
1
1
  module Flexipass
2
+ # Represents a door in the Flexipass system.
2
3
  class Door
4
+ # Initializes a new instance of the Door class.
5
+ #
6
+ # @param client [Object] The client object used to communicate with the Flexipass API.
3
7
  def initialize(client)
4
8
  @client = client
5
9
  end
6
10
 
11
+ # Retrieves a list of doors
12
+ #
13
+ # @return [Object] The response object containing the list of doors.
7
14
  def list
8
15
  @client.send_request('GET', '/Flexipass/rest/webapi/getDoorList')
9
16
  end
@@ -1,43 +1,97 @@
1
1
  module Flexipass
2
+ # Represents a mobile key in the Flexipass system.
2
3
  class MobileKey
4
+ # Initializes a new instance of the MobileKey class.
5
+ #
6
+ # @param client [Object] The client object used to communicate with the Flexipass API.
3
7
  def initialize(client)
4
8
  @client = client
5
9
  end
6
10
 
11
+ # Creates a new mobile key.
12
+ #
13
+ # @param params [Hash] The parameters for creating the mobile key.
14
+ # @option params [String] :Name The name of the mobile key holder.
15
+ # @option params [String] :Surname The surname of the mobile key holder.
16
+ # @option params [String] :Mail The email of the mobile key holder.
17
+ # @option params [String] :Door The door associated with the mobile key.
18
+ # @option params [String] :Checkin_date The check-in date of the mobile key.
19
+ # @option params [String] :Checkin_time The check-in time of the mobile key.
20
+ # @option params [String] :Checkout_date The check-out date of the mobile key.
21
+ # @option params [String] :Checkout_time The check-out time of the mobile key.
22
+ # @option params [Integer] :MobileKeyType The type of the mobile key (0 or 1).
23
+ # @raise [ArgumentError] If any required parameters are missing or if the date or time format is invalid.
7
24
  def create(params)
8
25
  validate_params(params)
9
26
  @client.send_request('POST', '/Flexipass/rest/webapi/createMobileKey', params)
10
27
  end
11
28
 
29
+ # Updates an existing mobile key.
30
+ #
31
+ # @param mobile_key_id [String] The ID of the mobile key to update.
32
+ # @param params [Hash] The parameters for updating the mobile key.
33
+ # @option params [String] :Name The name of the mobile key holder.
34
+ # @option params [String] :Surname The surname of the mobile key holder.
35
+ # @option params [String] :Mail The email of the mobile key holder.
36
+ # @option params [String] :Door The door associated with the mobile key.
37
+ # @option params [String] :Checkin_date The check-in date of the mobile key.
38
+ # @option params [String] :Checkin_time The check-in time of the mobile key.
39
+ # @option params [String] :Checkout_date The check-out date of the mobile key.
40
+ # @option params [String] :Checkout_time The check-out time of the mobile key.
41
+ # @option params [Integer] :MobileKeyType The type of the mobile key (0 or 1).
42
+ # @raise [ArgumentError] If any required parameters are missing or if the date or time format is invalid.
12
43
  def update(mobile_key_id, params)
13
44
  validate_params(params)
14
45
  @client.send_request('PUT', "/Flexipass/rest/webapi/updateMobileKey?mkID=#{mobile_key_id}", params)
15
46
  end
16
47
 
48
+ # Deletes a mobile key.
49
+ #
50
+ # @param mobile_key_id [String] The ID of the mobile key to delete.
17
51
  def delete(mobile_key_id)
18
52
  @client.send_request('DELETE', "/Flexipass/rest/webapi/deleteMobileKey?mkID=#{mobile_key_id}")
19
53
  end
20
54
 
55
+ # Lists mobile keys for a specific door.
56
+ #
57
+ # @param door [String] The door for which to list mobile keys.
58
+ # @param params [Hash] The parameters for listing mobile keys.
59
+ # @option params [String] :StartDate The start date for filtering mobile keys.
60
+ # @option params [String] :EndDate The end date for filtering mobile keys.
61
+ # @raise [ArgumentError] If the date format is invalid.
21
62
  def list(door, params)
22
63
  validate_list_params(params)
23
64
  params[:Door] = door
24
65
  @client.send_request('POST', "/Flexipass/rest/webapi/getMobileKeyList", params)
25
66
  end
26
67
 
68
+ # Retrieves details of a mobile key.
69
+ #
70
+ # @param mobile_key_id [String] The ID of the mobile key to retrieve details for.
27
71
  def details(mobile_key_id)
28
72
  @client.send_request('GET', "/Flexipass/rest/webapi/getMobileKeyDetails?mkID=#{mobile_key_id}")
29
73
  end
30
74
 
75
+ # Sends an email for a mobile key.
76
+ #
77
+ # @param mobile_key_id [String] The ID of the mobile key to send the email for.
31
78
  def send_mail(mobile_key_id)
32
79
  @client.send_request('GET', "/Flexipass/rest/webapi/sendMail?mkID=#{mobile_key_id}")
33
80
  end
34
81
 
82
+ # Sends an SMS for a mobile key.
83
+ #
84
+ # @param mobile_key_id [String] The ID of the mobile key to send the SMS for.
35
85
  def send_sms(mobile_key_id)
36
86
  @client.send_request('GET', "/Flexipass/rest/webapi/sendSMS?mkID=#{mobile_key_id}")
37
87
  end
38
88
 
39
89
  private
40
90
 
91
+ # Validates the parameters for creating or updating a mobile key.
92
+ #
93
+ # @param params [Hash] The parameters to validate.
94
+ # @raise [ArgumentError] If any required parameters are missing or if the date or time format is invalid.
41
95
  def validate_params(params)
42
96
  required_params = [:Name, :Surname, :Mail, :Door, :Checkin_date, :Checkin_time, :Checkout_date, :Checkout_time, :MobileKeyType]
43
97
  missing_params = required_params - params.keys.map(&:to_sym)
@@ -49,6 +103,12 @@ module Flexipass
49
103
  validate_mobile_key_type(params[:MobileKeyType])
50
104
  end
51
105
 
106
+ # Validates the date and time format.
107
+ #
108
+ # @param date [String] The date to validate.
109
+ # @param time [String] The time to validate.
110
+ # @param label [String] The label for the date or time (e.g., "Check-in").
111
+ # @raise [ArgumentError] If the date or time format is invalid.
52
112
  def validate_date_time(date, time, label)
53
113
  date_format = /^(\d{4}-\d{2}-\d{2})$/
54
114
  time_format = /^(\d{2}:\d{2}:\d{2})$/
@@ -63,6 +123,10 @@ module Flexipass
63
123
  end
64
124
  end
65
125
 
126
+ # Validates the parameters for listing mobile keys.
127
+ #
128
+ # @param params [Hash] The parameters to validate.
129
+ # @raise [ArgumentError] If the date format is invalid.
66
130
  def validate_list_params(params)
67
131
  date_time_format = /(\d{4})(\d{2})(\d{2})T(\d{2})(\d{2})$/
68
132
 
@@ -75,6 +139,10 @@ module Flexipass
75
139
  end
76
140
  end
77
141
 
142
+ # Validates the mobile key type.
143
+ #
144
+ # @param type [Integer] The mobile key type.
145
+ # @raise [ArgumentError] If the mobile key type is invalid.
78
146
  def validate_mobile_key_type(type)
79
147
  unless [0, 1].include?(type)
80
148
  raise ArgumentError, "Invalid MobileKeyType. Must be 0 or 1"
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Flexipass
4
- VERSION = "0.1.2"
4
+ VERSION = "0.1.4"
5
5
  end
data/lib/flexipass.rb CHANGED
@@ -9,12 +9,25 @@ require 'flexipass/company'
9
9
  require 'flexipass/api_error'
10
10
 
11
11
  module Flexipass
12
+ # The main module for Flexipass gem.
13
+ #
14
+ # This module provides configuration options for Flexipass.
12
15
  class Error < StandardError; end
13
16
 
14
17
  class << self
15
18
  attr_accessor :configuration
16
19
  end
17
20
 
21
+ # Configures Flexipass with the given options.
22
+ #
23
+ # Example:
24
+ # Flexipass.configure do |config|
25
+ # config.username = 'your_username'
26
+ # config.password = 'your_password'
27
+ # config.company_token = 'your_company_token'
28
+ # config.environment = :development # or :production
29
+ # config.enable_logging = true # optional, defaults to false
30
+ # end
18
31
  def self.configure
19
32
  self.configuration ||= Configuration.new
20
33
  yield(configuration)
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: flexipass
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 0.1.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kellen Kyros
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2024-07-19 00:00:00.000000000 Z
11
+ date: 2024-07-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: faraday
@@ -98,6 +98,20 @@ dependencies:
98
98
  - - "~>"
99
99
  - !ruby/object:Gem::Version
100
100
  version: '1.8'
101
+ - !ruby/object:Gem::Dependency
102
+ name: yard
103
+ requirement: !ruby/object:Gem::Requirement
104
+ requirements:
105
+ - - "~>"
106
+ - !ruby/object:Gem::Version
107
+ version: 0.9.36
108
+ type: :development
109
+ prerelease: false
110
+ version_requirements: !ruby/object:Gem::Requirement
111
+ requirements:
112
+ - - "~>"
113
+ - !ruby/object:Gem::Version
114
+ version: 0.9.36
101
115
  description: A Ruby gem allows you to easily interact with Flexipass APIs
102
116
  email:
103
117
  - kellenkyros@gmail.com