Class: Savvy::Cert::Client

Inherits:
Object
  • Object
show all
Defined in:
lib/savvy/cert/client.rb

Overview

A certifiable Savvy client

Author:

Since:

  • 0.2.0

Version:

  • 0.1

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(opts = {}) ⇒ Savvy::Cert::Client

A new instance of Client

Parameters:

  • opts (Hash) (defaults to: {})

    the options to initialize the Client with

Options Hash (opts):

  • :id (String)

    the Client id

  • :secret (String)

    the Client secret

  • :redirect_uri (String)

    the Client redirect_uri

  • :agent (String | nil)

    the Client agent

  • :version (String)

    the Client version

Since:

  • 0.2.0


46
47
48
49
50
51
52
53
54
# File 'lib/savvy/cert/client.rb', line 46

def initialize(opts = {})
  @name = opts[:name]
  @id = opts[:id]
  @secret = opts[:secret]
  @redirect_uri = opts[:redirect_uri]
  @agent = opts[:agent]
  @version = opts[:version]
  @errors = {}
end

Instance Attribute Details

#agentString

Returns the user_agent of the client

Returns:

  • (String)

    the user_agent of the client

Since:

  • 0.2.0


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
117
# File 'lib/savvy/cert/client.rb', line 34

class Client
  attr_accessor :name, :id, :secret, :redirect_uri, :agent, :version
  attr_reader :errors

  # A new instance of Client
  # @param opts [Hash] the options to initialize the Client with
  # @option opts [String] :id the Client id
  # @option opts [String] :secret the Client secret
  # @option opts [String] :redirect_uri the Client redirect_uri
  # @option opts [String | nil] :agent the Client agent
  # @option opts [String] :version the Client version
  # @return [Savvy::Cert::Client] an instance of Client
  def initialize(opts = {})
    @name = opts[:name]
    @id = opts[:id]
    @secret = opts[:secret]
    @redirect_uri = opts[:redirect_uri]
    @agent = opts[:agent]
    @version = opts[:version]
    @errors = {}
  end

  # Ensure Client is valid
  # @note
  #   * Validates that {name}, {id}, {secret}, {redirect_uri}, and {version} are present
  #   * Validates that {redirect_uri} is a valid url
  # @example Validate a Client
  #   # Being valid
  #   my_client = Client.new(name: 'My Awesome Application',
  #                          id: 'd58539ce114dfedf324fb1508e4db660',
  #                          secret: '64a6c90b9de9a85863eabaf828d123cc',
  #                          redirect_uri: 'https://my-awesome-app.com/oauth/callback',
  #                          agent: 'My Awesome Application/1.0.0',
  #                          version: '1.0.0')
  #   my_client.valid?
  #   #=> true
  #
  #   # Being invalid
  #   my_invalid_client = Client.new(name: 'My Awesome Application')
  #   my_invalid_client.valid?
  #   #=> false
  # @return [Boolean] whether or not the Client instance is valid
  def valid?
    validate_client
    errors.empty?
  end

  # Client to a json string
  # @example
  #   my_client.to_json
  #   #=> "{\"name\":\"My Awesome Application\",\"id\":\"d58539ce114dfedf324fb1508e4db660\", ...}"
  # @return [String] a json string
  def to_json
    client_hash = { name: name, id: id, secret: secret, redirect_uri: redirect_uri, version: version }
    client_hash[:agent] = agent if agent
    client_hash[:errors] = errors unless errors.empty?
    client_hash.to_json
  end

  private

  def validate_client
    validate_presence_of :name
    validate_presence_of :id
    validate_presence_of :secret
    validate_presence_of :redirect_uri
    validate_url_of :redirect_uri
    validate_presence_of :version
  end

  def add_error(column, msg)
    @errors[column] ||= []
    @errors[column] << msg
  end

  def validate_presence_of(column)
    add_error column, 'Cannot be blank' if instance_variable_get("@#{column}").nil?
  end

  def validate_url_of(column)
    url_val = instance_variable_get("@#{column}")
    add_error column, 'Invalid URL' unless url_val&.match? URI::DEFAULT_PARSER.make_regexp
  end
end

#errorsHash{Symbol => Array<String>} (readonly)

Returns A Hash of Client attributes and error messages

Examples:

A Client with errors

client = Client.new(name: 'My Awesome Application',
                    secret: '64a6c90b9de9a85863eabaf828d123cc',
                    redirect_uri: 'mycallback.com',
                    version: '0.1.0')
client.valid?
client.errors
#=> { id: ['Cannot be blank'], redirect_uri: ['Invalid URL'] }

Returns:

  • (Hash{Symbol => Array<String>})

    A Hash of Client attributes and error messages

Since:

  • 0.2.0


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
117
# File 'lib/savvy/cert/client.rb', line 34

class Client
  attr_accessor :name, :id, :secret, :redirect_uri, :agent, :version
  attr_reader :errors

  # A new instance of Client
  # @param opts [Hash] the options to initialize the Client with
  # @option opts [String] :id the Client id
  # @option opts [String] :secret the Client secret
  # @option opts [String] :redirect_uri the Client redirect_uri
  # @option opts [String | nil] :agent the Client agent
  # @option opts [String] :version the Client version
  # @return [Savvy::Cert::Client] an instance of Client
  def initialize(opts = {})
    @name = opts[:name]
    @id = opts[:id]
    @secret = opts[:secret]
    @redirect_uri = opts[:redirect_uri]
    @agent = opts[:agent]
    @version = opts[:version]
    @errors = {}
  end

  # Ensure Client is valid
  # @note
  #   * Validates that {name}, {id}, {secret}, {redirect_uri}, and {version} are present
  #   * Validates that {redirect_uri} is a valid url
  # @example Validate a Client
  #   # Being valid
  #   my_client = Client.new(name: 'My Awesome Application',
  #                          id: 'd58539ce114dfedf324fb1508e4db660',
  #                          secret: '64a6c90b9de9a85863eabaf828d123cc',
  #                          redirect_uri: 'https://my-awesome-app.com/oauth/callback',
  #                          agent: 'My Awesome Application/1.0.0',
  #                          version: '1.0.0')
  #   my_client.valid?
  #   #=> true
  #
  #   # Being invalid
  #   my_invalid_client = Client.new(name: 'My Awesome Application')
  #   my_invalid_client.valid?
  #   #=> false
  # @return [Boolean] whether or not the Client instance is valid
  def valid?
    validate_client
    errors.empty?
  end

  # Client to a json string
  # @example
  #   my_client.to_json
  #   #=> "{\"name\":\"My Awesome Application\",\"id\":\"d58539ce114dfedf324fb1508e4db660\", ...}"
  # @return [String] a json string
  def to_json
    client_hash = { name: name, id: id, secret: secret, redirect_uri: redirect_uri, version: version }
    client_hash[:agent] = agent if agent
    client_hash[:errors] = errors unless errors.empty?
    client_hash.to_json
  end

  private

  def validate_client
    validate_presence_of :name
    validate_presence_of :id
    validate_presence_of :secret
    validate_presence_of :redirect_uri
    validate_url_of :redirect_uri
    validate_presence_of :version
  end

  def add_error(column, msg)
    @errors[column] ||= []
    @errors[column] << msg
  end

  def validate_presence_of(column)
    add_error column, 'Cannot be blank' if instance_variable_get("@#{column}").nil?
  end

  def validate_url_of(column)
    url_val = instance_variable_get("@#{column}")
    add_error column, 'Invalid URL' unless url_val&.match? URI::DEFAULT_PARSER.make_regexp
  end
end

#idString

Returns the OAuth client_id of the client

Returns:

  • (String)

    the OAuth client_id of the client

Since:

  • 0.2.0


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
117
# File 'lib/savvy/cert/client.rb', line 34

class Client
  attr_accessor :name, :id, :secret, :redirect_uri, :agent, :version
  attr_reader :errors

  # A new instance of Client
  # @param opts [Hash] the options to initialize the Client with
  # @option opts [String] :id the Client id
  # @option opts [String] :secret the Client secret
  # @option opts [String] :redirect_uri the Client redirect_uri
  # @option opts [String | nil] :agent the Client agent
  # @option opts [String] :version the Client version
  # @return [Savvy::Cert::Client] an instance of Client
  def initialize(opts = {})
    @name = opts[:name]
    @id = opts[:id]
    @secret = opts[:secret]
    @redirect_uri = opts[:redirect_uri]
    @agent = opts[:agent]
    @version = opts[:version]
    @errors = {}
  end

  # Ensure Client is valid
  # @note
  #   * Validates that {name}, {id}, {secret}, {redirect_uri}, and {version} are present
  #   * Validates that {redirect_uri} is a valid url
  # @example Validate a Client
  #   # Being valid
  #   my_client = Client.new(name: 'My Awesome Application',
  #                          id: 'd58539ce114dfedf324fb1508e4db660',
  #                          secret: '64a6c90b9de9a85863eabaf828d123cc',
  #                          redirect_uri: 'https://my-awesome-app.com/oauth/callback',
  #                          agent: 'My Awesome Application/1.0.0',
  #                          version: '1.0.0')
  #   my_client.valid?
  #   #=> true
  #
  #   # Being invalid
  #   my_invalid_client = Client.new(name: 'My Awesome Application')
  #   my_invalid_client.valid?
  #   #=> false
  # @return [Boolean] whether or not the Client instance is valid
  def valid?
    validate_client
    errors.empty?
  end

  # Client to a json string
  # @example
  #   my_client.to_json
  #   #=> "{\"name\":\"My Awesome Application\",\"id\":\"d58539ce114dfedf324fb1508e4db660\", ...}"
  # @return [String] a json string
  def to_json
    client_hash = { name: name, id: id, secret: secret, redirect_uri: redirect_uri, version: version }
    client_hash[:agent] = agent if agent
    client_hash[:errors] = errors unless errors.empty?
    client_hash.to_json
  end

  private

  def validate_client
    validate_presence_of :name
    validate_presence_of :id
    validate_presence_of :secret
    validate_presence_of :redirect_uri
    validate_url_of :redirect_uri
    validate_presence_of :version
  end

  def add_error(column, msg)
    @errors[column] ||= []
    @errors[column] << msg
  end

  def validate_presence_of(column)
    add_error column, 'Cannot be blank' if instance_variable_get("@#{column}").nil?
  end

  def validate_url_of(column)
    url_val = instance_variable_get("@#{column}")
    add_error column, 'Invalid URL' unless url_val&.match? URI::DEFAULT_PARSER.make_regexp
  end
end

#nameString the name of the client

Returns String the name of the client

Returns:

  • (String the name of the client)

    String the name of the client

Since:

  • 0.2.0


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
117
# File 'lib/savvy/cert/client.rb', line 34

class Client
  attr_accessor :name, :id, :secret, :redirect_uri, :agent, :version
  attr_reader :errors

  # A new instance of Client
  # @param opts [Hash] the options to initialize the Client with
  # @option opts [String] :id the Client id
  # @option opts [String] :secret the Client secret
  # @option opts [String] :redirect_uri the Client redirect_uri
  # @option opts [String | nil] :agent the Client agent
  # @option opts [String] :version the Client version
  # @return [Savvy::Cert::Client] an instance of Client
  def initialize(opts = {})
    @name = opts[:name]
    @id = opts[:id]
    @secret = opts[:secret]
    @redirect_uri = opts[:redirect_uri]
    @agent = opts[:agent]
    @version = opts[:version]
    @errors = {}
  end

  # Ensure Client is valid
  # @note
  #   * Validates that {name}, {id}, {secret}, {redirect_uri}, and {version} are present
  #   * Validates that {redirect_uri} is a valid url
  # @example Validate a Client
  #   # Being valid
  #   my_client = Client.new(name: 'My Awesome Application',
  #                          id: 'd58539ce114dfedf324fb1508e4db660',
  #                          secret: '64a6c90b9de9a85863eabaf828d123cc',
  #                          redirect_uri: 'https://my-awesome-app.com/oauth/callback',
  #                          agent: 'My Awesome Application/1.0.0',
  #                          version: '1.0.0')
  #   my_client.valid?
  #   #=> true
  #
  #   # Being invalid
  #   my_invalid_client = Client.new(name: 'My Awesome Application')
  #   my_invalid_client.valid?
  #   #=> false
  # @return [Boolean] whether or not the Client instance is valid
  def valid?
    validate_client
    errors.empty?
  end

  # Client to a json string
  # @example
  #   my_client.to_json
  #   #=> "{\"name\":\"My Awesome Application\",\"id\":\"d58539ce114dfedf324fb1508e4db660\", ...}"
  # @return [String] a json string
  def to_json
    client_hash = { name: name, id: id, secret: secret, redirect_uri: redirect_uri, version: version }
    client_hash[:agent] = agent if agent
    client_hash[:errors] = errors unless errors.empty?
    client_hash.to_json
  end

  private

  def validate_client
    validate_presence_of :name
    validate_presence_of :id
    validate_presence_of :secret
    validate_presence_of :redirect_uri
    validate_url_of :redirect_uri
    validate_presence_of :version
  end

  def add_error(column, msg)
    @errors[column] ||= []
    @errors[column] << msg
  end

  def validate_presence_of(column)
    add_error column, 'Cannot be blank' if instance_variable_get("@#{column}").nil?
  end

  def validate_url_of(column)
    url_val = instance_variable_get("@#{column}")
    add_error column, 'Invalid URL' unless url_val&.match? URI::DEFAULT_PARSER.make_regexp
  end
end

#redirect_uriString

Returns the OAuth authorization callback of the client

Returns:

  • (String)

    the OAuth authorization callback of the client

Since:

  • 0.2.0


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
117
# File 'lib/savvy/cert/client.rb', line 34

class Client
  attr_accessor :name, :id, :secret, :redirect_uri, :agent, :version
  attr_reader :errors

  # A new instance of Client
  # @param opts [Hash] the options to initialize the Client with
  # @option opts [String] :id the Client id
  # @option opts [String] :secret the Client secret
  # @option opts [String] :redirect_uri the Client redirect_uri
  # @option opts [String | nil] :agent the Client agent
  # @option opts [String] :version the Client version
  # @return [Savvy::Cert::Client] an instance of Client
  def initialize(opts = {})
    @name = opts[:name]
    @id = opts[:id]
    @secret = opts[:secret]
    @redirect_uri = opts[:redirect_uri]
    @agent = opts[:agent]
    @version = opts[:version]
    @errors = {}
  end

  # Ensure Client is valid
  # @note
  #   * Validates that {name}, {id}, {secret}, {redirect_uri}, and {version} are present
  #   * Validates that {redirect_uri} is a valid url
  # @example Validate a Client
  #   # Being valid
  #   my_client = Client.new(name: 'My Awesome Application',
  #                          id: 'd58539ce114dfedf324fb1508e4db660',
  #                          secret: '64a6c90b9de9a85863eabaf828d123cc',
  #                          redirect_uri: 'https://my-awesome-app.com/oauth/callback',
  #                          agent: 'My Awesome Application/1.0.0',
  #                          version: '1.0.0')
  #   my_client.valid?
  #   #=> true
  #
  #   # Being invalid
  #   my_invalid_client = Client.new(name: 'My Awesome Application')
  #   my_invalid_client.valid?
  #   #=> false
  # @return [Boolean] whether or not the Client instance is valid
  def valid?
    validate_client
    errors.empty?
  end

  # Client to a json string
  # @example
  #   my_client.to_json
  #   #=> "{\"name\":\"My Awesome Application\",\"id\":\"d58539ce114dfedf324fb1508e4db660\", ...}"
  # @return [String] a json string
  def to_json
    client_hash = { name: name, id: id, secret: secret, redirect_uri: redirect_uri, version: version }
    client_hash[:agent] = agent if agent
    client_hash[:errors] = errors unless errors.empty?
    client_hash.to_json
  end

  private

  def validate_client
    validate_presence_of :name
    validate_presence_of :id
    validate_presence_of :secret
    validate_presence_of :redirect_uri
    validate_url_of :redirect_uri
    validate_presence_of :version
  end

  def add_error(column, msg)
    @errors[column] ||= []
    @errors[column] << msg
  end

  def validate_presence_of(column)
    add_error column, 'Cannot be blank' if instance_variable_get("@#{column}").nil?
  end

  def validate_url_of(column)
    url_val = instance_variable_get("@#{column}")
    add_error column, 'Invalid URL' unless url_val&.match? URI::DEFAULT_PARSER.make_regexp
  end
end

#secretString

Returns the OAuth client_secret of the client

Returns:

  • (String)

    the OAuth client_secret of the client

Since:

  • 0.2.0


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
117
# File 'lib/savvy/cert/client.rb', line 34

class Client
  attr_accessor :name, :id, :secret, :redirect_uri, :agent, :version
  attr_reader :errors

  # A new instance of Client
  # @param opts [Hash] the options to initialize the Client with
  # @option opts [String] :id the Client id
  # @option opts [String] :secret the Client secret
  # @option opts [String] :redirect_uri the Client redirect_uri
  # @option opts [String | nil] :agent the Client agent
  # @option opts [String] :version the Client version
  # @return [Savvy::Cert::Client] an instance of Client
  def initialize(opts = {})
    @name = opts[:name]
    @id = opts[:id]
    @secret = opts[:secret]
    @redirect_uri = opts[:redirect_uri]
    @agent = opts[:agent]
    @version = opts[:version]
    @errors = {}
  end

  # Ensure Client is valid
  # @note
  #   * Validates that {name}, {id}, {secret}, {redirect_uri}, and {version} are present
  #   * Validates that {redirect_uri} is a valid url
  # @example Validate a Client
  #   # Being valid
  #   my_client = Client.new(name: 'My Awesome Application',
  #                          id: 'd58539ce114dfedf324fb1508e4db660',
  #                          secret: '64a6c90b9de9a85863eabaf828d123cc',
  #                          redirect_uri: 'https://my-awesome-app.com/oauth/callback',
  #                          agent: 'My Awesome Application/1.0.0',
  #                          version: '1.0.0')
  #   my_client.valid?
  #   #=> true
  #
  #   # Being invalid
  #   my_invalid_client = Client.new(name: 'My Awesome Application')
  #   my_invalid_client.valid?
  #   #=> false
  # @return [Boolean] whether or not the Client instance is valid
  def valid?
    validate_client
    errors.empty?
  end

  # Client to a json string
  # @example
  #   my_client.to_json
  #   #=> "{\"name\":\"My Awesome Application\",\"id\":\"d58539ce114dfedf324fb1508e4db660\", ...}"
  # @return [String] a json string
  def to_json
    client_hash = { name: name, id: id, secret: secret, redirect_uri: redirect_uri, version: version }
    client_hash[:agent] = agent if agent
    client_hash[:errors] = errors unless errors.empty?
    client_hash.to_json
  end

  private

  def validate_client
    validate_presence_of :name
    validate_presence_of :id
    validate_presence_of :secret
    validate_presence_of :redirect_uri
    validate_url_of :redirect_uri
    validate_presence_of :version
  end

  def add_error(column, msg)
    @errors[column] ||= []
    @errors[column] << msg
  end

  def validate_presence_of(column)
    add_error column, 'Cannot be blank' if instance_variable_get("@#{column}").nil?
  end

  def validate_url_of(column)
    url_val = instance_variable_get("@#{column}")
    add_error column, 'Invalid URL' unless url_val&.match? URI::DEFAULT_PARSER.make_regexp
  end
end

#versionString

Returns the client version

Returns:

  • (String)

    the client version

Since:

  • 0.2.0


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
117
# File 'lib/savvy/cert/client.rb', line 34

class Client
  attr_accessor :name, :id, :secret, :redirect_uri, :agent, :version
  attr_reader :errors

  # A new instance of Client
  # @param opts [Hash] the options to initialize the Client with
  # @option opts [String] :id the Client id
  # @option opts [String] :secret the Client secret
  # @option opts [String] :redirect_uri the Client redirect_uri
  # @option opts [String | nil] :agent the Client agent
  # @option opts [String] :version the Client version
  # @return [Savvy::Cert::Client] an instance of Client
  def initialize(opts = {})
    @name = opts[:name]
    @id = opts[:id]
    @secret = opts[:secret]
    @redirect_uri = opts[:redirect_uri]
    @agent = opts[:agent]
    @version = opts[:version]
    @errors = {}
  end

  # Ensure Client is valid
  # @note
  #   * Validates that {name}, {id}, {secret}, {redirect_uri}, and {version} are present
  #   * Validates that {redirect_uri} is a valid url
  # @example Validate a Client
  #   # Being valid
  #   my_client = Client.new(name: 'My Awesome Application',
  #                          id: 'd58539ce114dfedf324fb1508e4db660',
  #                          secret: '64a6c90b9de9a85863eabaf828d123cc',
  #                          redirect_uri: 'https://my-awesome-app.com/oauth/callback',
  #                          agent: 'My Awesome Application/1.0.0',
  #                          version: '1.0.0')
  #   my_client.valid?
  #   #=> true
  #
  #   # Being invalid
  #   my_invalid_client = Client.new(name: 'My Awesome Application')
  #   my_invalid_client.valid?
  #   #=> false
  # @return [Boolean] whether or not the Client instance is valid
  def valid?
    validate_client
    errors.empty?
  end

  # Client to a json string
  # @example
  #   my_client.to_json
  #   #=> "{\"name\":\"My Awesome Application\",\"id\":\"d58539ce114dfedf324fb1508e4db660\", ...}"
  # @return [String] a json string
  def to_json
    client_hash = { name: name, id: id, secret: secret, redirect_uri: redirect_uri, version: version }
    client_hash[:agent] = agent if agent
    client_hash[:errors] = errors unless errors.empty?
    client_hash.to_json
  end

  private

  def validate_client
    validate_presence_of :name
    validate_presence_of :id
    validate_presence_of :secret
    validate_presence_of :redirect_uri
    validate_url_of :redirect_uri
    validate_presence_of :version
  end

  def add_error(column, msg)
    @errors[column] ||= []
    @errors[column] << msg
  end

  def validate_presence_of(column)
    add_error column, 'Cannot be blank' if instance_variable_get("@#{column}").nil?
  end

  def validate_url_of(column)
    url_val = instance_variable_get("@#{column}")
    add_error column, 'Invalid URL' unless url_val&.match? URI::DEFAULT_PARSER.make_regexp
  end
end

Instance Method Details

#to_jsonString

Client to a json string

Examples:

my_client.to_json
#=> "{\"name\":\"My Awesome Application\",\"id\":\"d58539ce114dfedf324fb1508e4db660\", ...}"

Returns:

  • (String)

    a json string

Since:

  • 0.2.0


86
87
88
89
90
91
# File 'lib/savvy/cert/client.rb', line 86

def to_json
  client_hash = { name: name, id: id, secret: secret, redirect_uri: redirect_uri, version: version }
  client_hash[:agent] = agent if agent
  client_hash[:errors] = errors unless errors.empty?
  client_hash.to_json
end

#valid?Boolean

Note:

Ensure Client is valid

Examples:

Validate a Client

# Being valid
my_client = Client.new(name: 'My Awesome Application',
                       id: 'd58539ce114dfedf324fb1508e4db660',
                       secret: '64a6c90b9de9a85863eabaf828d123cc',
                       redirect_uri: 'https://my-awesome-app.com/oauth/callback',
                       agent: 'My Awesome Application/1.0.0',
                       version: '1.0.0')
my_client.valid?
#=> true

# Being invalid
my_invalid_client = Client.new(name: 'My Awesome Application')
my_invalid_client.valid?
#=> false

Returns:

  • (Boolean)

    whether or not the Client instance is valid

Since:

  • 0.2.0


76
77
78
79
# File 'lib/savvy/cert/client.rb', line 76

def valid?
  validate_client
  errors.empty?
end