Class: InsalesApi::App
- Inherits:
-
Object
- Object
- InsalesApi::App
- Defined in:
- lib/insales_api/app.rb
Instance Attribute Summary collapse
-
#authorized ⇒ Object
readonly
Returns the value of attribute authorized.
-
#domain ⇒ Object
(also: #shop)
readonly
Returns the value of attribute domain.
-
#password ⇒ Object
readonly
Returns the value of attribute password.
Class Method Summary collapse
- .configure_api(domain, password) ⇒ Object
-
.install(domain, token, insales_id) ⇒ Object
rubocop:disable Lint/UnusedMethodArgument.
- .password_by_token(token) ⇒ Object
- .prepare_domain(domain) ⇒ Object (also: prepare_shop)
-
.uninstall(domain, password) ⇒ Object
rubocop:disable Lint/UnusedMethodArgument.
Instance Method Summary collapse
- #auth_token(salt = self.salt, user_email = '', user_name = '', user_id = '') ⇒ Object (also: #store_auth_token)
- #authorization_url ⇒ Object
- #authorize(token) ⇒ Object
- #authorized? ⇒ Boolean
- #configure_api ⇒ Object
-
#initialize(domain, password) ⇒ App
constructor
A new instance of App.
- #salt ⇒ Object
Constructor Details
#initialize(domain, password) ⇒ App
Returns a new instance of App.
39 40 41 42 43 |
# File 'lib/insales_api/app.rb', line 39 def initialize(domain, password) @authorized = false @domain = self.class.prepare_domain(domain) @password = password end |
Instance Attribute Details
#authorized ⇒ Object (readonly)
Returns the value of attribute authorized.
5 6 7 |
# File 'lib/insales_api/app.rb', line 5 def @authorized end |
#domain ⇒ Object (readonly) Also known as: shop
Returns the value of attribute domain.
5 6 7 |
# File 'lib/insales_api/app.rb', line 5 def domain @domain end |
#password ⇒ Object (readonly)
Returns the value of attribute password.
5 6 7 |
# File 'lib/insales_api/app.rb', line 5 def password @password end |
Class Method Details
.configure_api(domain, password) ⇒ Object
10 11 12 |
# File 'lib/insales_api/app.rb', line 10 def configure_api(domain, password) base_resource_class.configure(api_key, domain, password) end |
.install(domain, token, insales_id) ⇒ Object
rubocop:disable Lint/UnusedMethodArgument
26 27 28 |
# File 'lib/insales_api/app.rb', line 26 def install(domain, token, insales_id) # rubocop:disable Lint/UnusedMethodArgument true end |
.password_by_token(token) ⇒ Object
34 35 36 |
# File 'lib/insales_api/app.rb', line 34 def password_by_token(token) InsalesApi::Password.create(api_secret, token) end |
.prepare_domain(domain) ⇒ Object Also known as: prepare_shop
16 17 18 |
# File 'lib/insales_api/app.rb', line 16 def prepare_domain(domain) domain.to_s.strip.downcase end |
.uninstall(domain, password) ⇒ Object
rubocop:disable Lint/UnusedMethodArgument
30 31 32 |
# File 'lib/insales_api/app.rb', line 30 def uninstall(domain, password) # rubocop:disable Lint/UnusedMethodArgument true end |
Instance Method Details
#auth_token(salt = self.salt, user_email = '', user_name = '', user_id = '') ⇒ Object Also known as: store_auth_token
61 62 63 |
# File 'lib/insales_api/app.rb', line 61 def auth_token(salt = self.salt, user_email = '', user_name = '', user_id = '') @auth_token ||= InsalesApi::Password.create(password, salt, user_email, user_name, user_id) end |
#authorization_url ⇒ Object
45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/insales_api/app.rb', line 45 def host, port = domain, nil match = /(.+):(\d+)/.match host host, port = match[1..2] if match URI::Generic.build( scheme: 'http', host: host, port: port && port.to_i, path: "/admin/applications/#{api_key}/login", query: { token: salt, login: api_autologin_url || "http://#{api_host}/#{api_autologin_path}", }.to_query, ).to_s end |
#authorize(token) ⇒ Object
69 70 71 |
# File 'lib/insales_api/app.rb', line 69 def (token) @authorized = auth_token == token end |
#authorized? ⇒ Boolean
73 74 75 |
# File 'lib/insales_api/app.rb', line 73 def @authorized end |
#configure_api ⇒ Object
77 78 79 |
# File 'lib/insales_api/app.rb', line 77 def configure_api self.class.configure_api(domain, password) end |
#salt ⇒ Object
65 66 67 |
# File 'lib/insales_api/app.rb', line 65 def salt @salt ||= SecureRandom.hex end |