Class: Etwin::Oauth::ShortOauthClient

Inherits:
Object
  • Object
show all
Extended by:
T::Helpers, T::Sig
Defined in:
lib/etwin/oauth/short_oauth_client.rb

Overview

OAuth client with minimum data to identify and display it

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(id, key, display_name) ⇒ ShortOauthClient

Returns a new instance of ShortOauthClient.



23
24
25
26
27
28
# File 'lib/etwin/oauth/short_oauth_client.rb', line 23

def initialize(id, key, display_name)
  @id = T.let(id, OauthClientId)
  @key = T.let(key, T.nilable(OauthClientKey))
  @display_name = T.let(display_name, OauthClientDisplayName)
  freeze
end

Instance Attribute Details

#display_nameObject (readonly)

Returns the value of attribute display_name.



20
21
22
# File 'lib/etwin/oauth/short_oauth_client.rb', line 20

def display_name
  @display_name
end

#idObject (readonly)

Returns the value of attribute id.



14
15
16
# File 'lib/etwin/oauth/short_oauth_client.rb', line 14

def id
  @id
end

#keyObject (readonly)

Returns the value of attribute key.



17
18
19
# File 'lib/etwin/oauth/short_oauth_client.rb', line 17

def key
  @key
end

Class Method Details

.deserialize(raw) ⇒ Object



94
95
96
97
98
99
100
# File 'lib/etwin/oauth/short_oauth_client.rb', line 94

def deserialize(raw)
  id = OauthClientId.new(raw['id'])
  raw_key = raw['key']
  key = raw_key.nil? ? nil : OauthClientKey.new(raw_key)
  display_name = OauthClientDisplayName.new(raw['display_name'])
  new(id, key, display_name)
end

.from_json(json_str) ⇒ Object



89
90
91
# File 'lib/etwin/oauth/short_oauth_client.rb', line 89

def from_json(json_str)
  deserialize JSON.parse(json_str)
end

Instance Method Details

#==(other) ⇒ Object



31
32
33
34
35
36
37
38
# File 'lib/etwin/oauth/short_oauth_client.rb', line 31

def ==(other)
  case other
  when ShortOauthClient
    @id == other.id && @key == other.key && @display_name == other.display_name
  else
    false
  end
end

#as_jsonObject



52
53
54
55
56
57
58
# File 'lib/etwin/oauth/short_oauth_client.rb', line 52

def as_json
  {
    'id' => @id.as_json,
    'key' => @key.nil? ? nil : @key.as_json,
    'display_name' => @display_name.as_json
  }
end

#hashObject



41
42
43
# File 'lib/etwin/oauth/short_oauth_client.rb', line 41

def hash
  [@id, @key, @display_name].hash
end

#inspectObject



61
62
63
# File 'lib/etwin/oauth/short_oauth_client.rb', line 61

def inspect
  PP.singleline_pp(self, String.new)
end

#pretty_print(pp) ⇒ Object

rubocop:disable Metrics/MethodLength



66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
# File 'lib/etwin/oauth/short_oauth_client.rb', line 66

def pretty_print(pp)  # rubocop:disable Metrics/MethodLength
  pp.group(0, "#{self.class.name}(", ')') do
    pp.nest 1 do
      pp.breakable ''
      pp.text 'id='
      pp.pp @id
      pp.text ','
      pp.breakable ''
      pp.text 'key='
      pp.pp @key
      pp.text ','
      pp.breakable ''
      pp.text 'display_name='
      pp.pp @display_name
    end
    pp.breakable ''
  end
end

#to_json(opts = nil) ⇒ Object



47
48
49
# File 'lib/etwin/oauth/short_oauth_client.rb', line 47

def to_json(opts = nil)
  JSON.generate(as_json, opts)
end