Class: FreightKit::Credential
- Defined in:
- lib/freight_kit/models/credential.rb
Overview
Class representing credentials.
Instance Attribute Summary collapse
-
#access_token ⇒ String
Access token when type is ‘:oauth2`.
-
#expires_at ⇒ DateTime
Token expiration date/time when type is ‘:oauth2`.
-
#kind ⇒ Symbol
What kind?.
-
#password ⇒ String
Password when type is one of ‘:api`, `:website`.
-
#scope ⇒ String
Scope when type is ‘:oauth2`.
-
#type ⇒ Object
Returns the value of attribute type.
-
#username ⇒ String
Username when type is one of ‘:api`, `:website`.
Instance Method Summary collapse
-
#initialize(hash) ⇒ Credential
constructor
Returns a new instance of Credential.
- #selenoid_options ⇒ Object
- #watir_args ⇒ Object
Methods inherited from Model
Constructor Details
#initialize(hash) ⇒ Credential
Returns a new instance of Credential.
Other than the following, instance ‘:attr_reader`s are generated dynamically based on keys.
45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 |
# File 'lib/freight_kit/models/credential.rb', line 45 def initialize(hash) raise ArgumentError, 'Credential#new: `type` cannot be blank' if hash[:type].blank? type = hash[:type] requirements = case type when :api_key { api_key: String } when :api, :website { password: String } when :api_proxy { api_key: String, proxy_url: String } when :oauth2 { access_token: String, expires_at: ::DateTime, scope: String } when :selenoid { base_url: URI, browser: Symbol } else {} end requirements.each_key do |k| raise ArgumentError, "Credential#new: `#{k}` cannot be blank" if hash[k].blank? unless hash[k].is_a?(requirements[k]) raise ArgumentError, "Credential#new: `#{k}` must be a #{requirements[k]}, got #{hash[k].class}" end end hash.each do |k, _v| next if k == :type singleton_class.class_eval { attr_accessor(k.to_s) } unless singleton_class.respond_to?(k) end super end |
Instance Attribute Details
#access_token ⇒ String
Access token when type is ‘:oauth2`
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 |
# File 'lib/freight_kit/models/credential.rb', line 30 class Credential < Model attr_accessor :type # Returns a new instance of Credential. # # Other than the following, instance `:attr_reader`s are generated dynamically based on keys. # # @param [Symbol] type One of `:api`, `:website` # @param [String] base_url Required when type is `:selenoid` # @param [String] username Required when type is one of `:api`, `:website` # @param [String] password Required when type is one of `:api`, `:website` # @param [String] access_token Required when type is `:oauth2` # @param [DateTime] expires_at Required when type is `:oauth2` # @param [String] scope Required when type is `:oauth2` # @param [String] proxy_url Required when type is `:api_proxy` def initialize(hash) raise ArgumentError, 'Credential#new: `type` cannot be blank' if hash[:type].blank? type = hash[:type] requirements = case type when :api_key { api_key: String } when :api, :website { password: String } when :api_proxy { api_key: String, proxy_url: String } when :oauth2 { access_token: String, expires_at: ::DateTime, scope: String } when :selenoid { base_url: URI, browser: Symbol } else {} end requirements.each_key do |k| raise ArgumentError, "Credential#new: `#{k}` cannot be blank" if hash[k].blank? unless hash[k].is_a?(requirements[k]) raise ArgumentError, "Credential#new: `#{k}` must be a #{requirements[k]}, got #{hash[k].class}" end end hash.each do |k, _v| next if k == :type singleton_class.class_eval { attr_accessor(k.to_s) } unless singleton_class.respond_to?(k) end super end def return unless type == :selenoid return @selenoid_options if @selenoid_options.present? download_url = base_url.dup download_url.path = '/download' download_url = download_url.to_s @selenoid_options = { download_url: } end def watir_args return unless type == :selenoid return @watir_args if @watir_args.present? url = base_url.dup url.path = '/wd/hub/' url = url.to_s @watir_args = [ browser, { options: { prefs: { download: { directory_upgrade: true, prompt_for_download: false } } }, url: }, ] end end |
#expires_at ⇒ DateTime
Token expiration date/time when type is ‘:oauth2`
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 |
# File 'lib/freight_kit/models/credential.rb', line 30 class Credential < Model attr_accessor :type # Returns a new instance of Credential. # # Other than the following, instance `:attr_reader`s are generated dynamically based on keys. # # @param [Symbol] type One of `:api`, `:website` # @param [String] base_url Required when type is `:selenoid` # @param [String] username Required when type is one of `:api`, `:website` # @param [String] password Required when type is one of `:api`, `:website` # @param [String] access_token Required when type is `:oauth2` # @param [DateTime] expires_at Required when type is `:oauth2` # @param [String] scope Required when type is `:oauth2` # @param [String] proxy_url Required when type is `:api_proxy` def initialize(hash) raise ArgumentError, 'Credential#new: `type` cannot be blank' if hash[:type].blank? type = hash[:type] requirements = case type when :api_key { api_key: String } when :api, :website { password: String } when :api_proxy { api_key: String, proxy_url: String } when :oauth2 { access_token: String, expires_at: ::DateTime, scope: String } when :selenoid { base_url: URI, browser: Symbol } else {} end requirements.each_key do |k| raise ArgumentError, "Credential#new: `#{k}` cannot be blank" if hash[k].blank? unless hash[k].is_a?(requirements[k]) raise ArgumentError, "Credential#new: `#{k}` must be a #{requirements[k]}, got #{hash[k].class}" end end hash.each do |k, _v| next if k == :type singleton_class.class_eval { attr_accessor(k.to_s) } unless singleton_class.respond_to?(k) end super end def return unless type == :selenoid return @selenoid_options if @selenoid_options.present? download_url = base_url.dup download_url.path = '/download' download_url = download_url.to_s @selenoid_options = { download_url: } end def watir_args return unless type == :selenoid return @watir_args if @watir_args.present? url = base_url.dup url.path = '/wd/hub/' url = url.to_s @watir_args = [ browser, { options: { prefs: { download: { directory_upgrade: true, prompt_for_download: false } } }, url: }, ] end end |
#kind ⇒ Symbol
What kind?
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 |
# File 'lib/freight_kit/models/credential.rb', line 30 class Credential < Model attr_accessor :type # Returns a new instance of Credential. # # Other than the following, instance `:attr_reader`s are generated dynamically based on keys. # # @param [Symbol] type One of `:api`, `:website` # @param [String] base_url Required when type is `:selenoid` # @param [String] username Required when type is one of `:api`, `:website` # @param [String] password Required when type is one of `:api`, `:website` # @param [String] access_token Required when type is `:oauth2` # @param [DateTime] expires_at Required when type is `:oauth2` # @param [String] scope Required when type is `:oauth2` # @param [String] proxy_url Required when type is `:api_proxy` def initialize(hash) raise ArgumentError, 'Credential#new: `type` cannot be blank' if hash[:type].blank? type = hash[:type] requirements = case type when :api_key { api_key: String } when :api, :website { password: String } when :api_proxy { api_key: String, proxy_url: String } when :oauth2 { access_token: String, expires_at: ::DateTime, scope: String } when :selenoid { base_url: URI, browser: Symbol } else {} end requirements.each_key do |k| raise ArgumentError, "Credential#new: `#{k}` cannot be blank" if hash[k].blank? unless hash[k].is_a?(requirements[k]) raise ArgumentError, "Credential#new: `#{k}` must be a #{requirements[k]}, got #{hash[k].class}" end end hash.each do |k, _v| next if k == :type singleton_class.class_eval { attr_accessor(k.to_s) } unless singleton_class.respond_to?(k) end super end def return unless type == :selenoid return @selenoid_options if @selenoid_options.present? download_url = base_url.dup download_url.path = '/download' download_url = download_url.to_s @selenoid_options = { download_url: } end def watir_args return unless type == :selenoid return @watir_args if @watir_args.present? url = base_url.dup url.path = '/wd/hub/' url = url.to_s @watir_args = [ browser, { options: { prefs: { download: { directory_upgrade: true, prompt_for_download: false } } }, url: }, ] end end |
#password ⇒ String
Password when type is one of ‘:api`, `:website`
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 |
# File 'lib/freight_kit/models/credential.rb', line 30 class Credential < Model attr_accessor :type # Returns a new instance of Credential. # # Other than the following, instance `:attr_reader`s are generated dynamically based on keys. # # @param [Symbol] type One of `:api`, `:website` # @param [String] base_url Required when type is `:selenoid` # @param [String] username Required when type is one of `:api`, `:website` # @param [String] password Required when type is one of `:api`, `:website` # @param [String] access_token Required when type is `:oauth2` # @param [DateTime] expires_at Required when type is `:oauth2` # @param [String] scope Required when type is `:oauth2` # @param [String] proxy_url Required when type is `:api_proxy` def initialize(hash) raise ArgumentError, 'Credential#new: `type` cannot be blank' if hash[:type].blank? type = hash[:type] requirements = case type when :api_key { api_key: String } when :api, :website { password: String } when :api_proxy { api_key: String, proxy_url: String } when :oauth2 { access_token: String, expires_at: ::DateTime, scope: String } when :selenoid { base_url: URI, browser: Symbol } else {} end requirements.each_key do |k| raise ArgumentError, "Credential#new: `#{k}` cannot be blank" if hash[k].blank? unless hash[k].is_a?(requirements[k]) raise ArgumentError, "Credential#new: `#{k}` must be a #{requirements[k]}, got #{hash[k].class}" end end hash.each do |k, _v| next if k == :type singleton_class.class_eval { attr_accessor(k.to_s) } unless singleton_class.respond_to?(k) end super end def return unless type == :selenoid return @selenoid_options if @selenoid_options.present? download_url = base_url.dup download_url.path = '/download' download_url = download_url.to_s @selenoid_options = { download_url: } end def watir_args return unless type == :selenoid return @watir_args if @watir_args.present? url = base_url.dup url.path = '/wd/hub/' url = url.to_s @watir_args = [ browser, { options: { prefs: { download: { directory_upgrade: true, prompt_for_download: false } } }, url: }, ] end end |
#scope ⇒ String
Scope when type is ‘:oauth2`
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 |
# File 'lib/freight_kit/models/credential.rb', line 30 class Credential < Model attr_accessor :type # Returns a new instance of Credential. # # Other than the following, instance `:attr_reader`s are generated dynamically based on keys. # # @param [Symbol] type One of `:api`, `:website` # @param [String] base_url Required when type is `:selenoid` # @param [String] username Required when type is one of `:api`, `:website` # @param [String] password Required when type is one of `:api`, `:website` # @param [String] access_token Required when type is `:oauth2` # @param [DateTime] expires_at Required when type is `:oauth2` # @param [String] scope Required when type is `:oauth2` # @param [String] proxy_url Required when type is `:api_proxy` def initialize(hash) raise ArgumentError, 'Credential#new: `type` cannot be blank' if hash[:type].blank? type = hash[:type] requirements = case type when :api_key { api_key: String } when :api, :website { password: String } when :api_proxy { api_key: String, proxy_url: String } when :oauth2 { access_token: String, expires_at: ::DateTime, scope: String } when :selenoid { base_url: URI, browser: Symbol } else {} end requirements.each_key do |k| raise ArgumentError, "Credential#new: `#{k}` cannot be blank" if hash[k].blank? unless hash[k].is_a?(requirements[k]) raise ArgumentError, "Credential#new: `#{k}` must be a #{requirements[k]}, got #{hash[k].class}" end end hash.each do |k, _v| next if k == :type singleton_class.class_eval { attr_accessor(k.to_s) } unless singleton_class.respond_to?(k) end super end def return unless type == :selenoid return @selenoid_options if @selenoid_options.present? download_url = base_url.dup download_url.path = '/download' download_url = download_url.to_s @selenoid_options = { download_url: } end def watir_args return unless type == :selenoid return @watir_args if @watir_args.present? url = base_url.dup url.path = '/wd/hub/' url = url.to_s @watir_args = [ browser, { options: { prefs: { download: { directory_upgrade: true, prompt_for_download: false } } }, url: }, ] end end |
#type ⇒ Object
Returns the value of attribute type.
31 32 33 |
# File 'lib/freight_kit/models/credential.rb', line 31 def type @type end |
#username ⇒ String
Username when type is one of ‘:api`, `:website`
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 |
# File 'lib/freight_kit/models/credential.rb', line 30 class Credential < Model attr_accessor :type # Returns a new instance of Credential. # # Other than the following, instance `:attr_reader`s are generated dynamically based on keys. # # @param [Symbol] type One of `:api`, `:website` # @param [String] base_url Required when type is `:selenoid` # @param [String] username Required when type is one of `:api`, `:website` # @param [String] password Required when type is one of `:api`, `:website` # @param [String] access_token Required when type is `:oauth2` # @param [DateTime] expires_at Required when type is `:oauth2` # @param [String] scope Required when type is `:oauth2` # @param [String] proxy_url Required when type is `:api_proxy` def initialize(hash) raise ArgumentError, 'Credential#new: `type` cannot be blank' if hash[:type].blank? type = hash[:type] requirements = case type when :api_key { api_key: String } when :api, :website { password: String } when :api_proxy { api_key: String, proxy_url: String } when :oauth2 { access_token: String, expires_at: ::DateTime, scope: String } when :selenoid { base_url: URI, browser: Symbol } else {} end requirements.each_key do |k| raise ArgumentError, "Credential#new: `#{k}` cannot be blank" if hash[k].blank? unless hash[k].is_a?(requirements[k]) raise ArgumentError, "Credential#new: `#{k}` must be a #{requirements[k]}, got #{hash[k].class}" end end hash.each do |k, _v| next if k == :type singleton_class.class_eval { attr_accessor(k.to_s) } unless singleton_class.respond_to?(k) end super end def return unless type == :selenoid return @selenoid_options if @selenoid_options.present? download_url = base_url.dup download_url.path = '/download' download_url = download_url.to_s @selenoid_options = { download_url: } end def watir_args return unless type == :selenoid return @watir_args if @watir_args.present? url = base_url.dup url.path = '/wd/hub/' url = url.to_s @watir_args = [ browser, { options: { prefs: { download: { directory_upgrade: true, prompt_for_download: false } } }, url: }, ] end end |
Instance Method Details
#selenoid_options ⇒ Object
82 83 84 85 86 87 88 89 90 91 |
# File 'lib/freight_kit/models/credential.rb', line 82 def return unless type == :selenoid return @selenoid_options if @selenoid_options.present? download_url = base_url.dup download_url.path = '/download' download_url = download_url.to_s @selenoid_options = { download_url: } end |
#watir_args ⇒ Object
93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 |
# File 'lib/freight_kit/models/credential.rb', line 93 def watir_args return unless type == :selenoid return @watir_args if @watir_args.present? url = base_url.dup url.path = '/wd/hub/' url = url.to_s @watir_args = [ browser, { options: { prefs: { download: { directory_upgrade: true, prompt_for_download: false } } }, url: }, ] end |