Class: GoToWebinar::Client

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(organizer_key: nil, url: nil) ⇒ Client

Returns a new instance of Client.



5
6
7
8
9
10
11
# File 'lib/go_to_webinar/client.rb', line 5

def initialize(organizer_key: nil, url: nil)
  config = GoToWebinar.configuration
  @url = url || config.url
  @organizer_key = organizer_key || config.organizer_key
  @g2w_oauth2_client = GoToWebinar::Auth::Client.new
  @access_token = @g2w_oauth2_client.access_token&.token || config.access_token
end

Instance Attribute Details

#access_tokenObject

Returns the value of attribute access_token.



3
4
5
# File 'lib/go_to_webinar/client.rb', line 3

def access_token
  @access_token
end

#organizer_keyObject

Returns the value of attribute organizer_key.



3
4
5
# File 'lib/go_to_webinar/client.rb', line 3

def organizer_key
  @organizer_key
end

#urlObject

Returns the value of attribute url.



3
4
5
# File 'lib/go_to_webinar/client.rb', line 3

def url
  @url
end

Instance Method Details

#deleteObject



32
33
34
# File 'lib/go_to_webinar/client.rb', line 32

def delete
  attempt { parse(RestClient.delete(make_path(path), data, headers)) }
end

#get(path, data = {}) ⇒ Object



20
21
22
# File 'lib/go_to_webinar/client.rb', line 20

def get(path, data = {})
  attempt { parse(RestClient.get(make_path(path), data.merge(headers))) }
end

#headersObject



13
14
15
16
17
18
# File 'lib/go_to_webinar/client.rb', line 13

def headers
  {
    'Accept' => 'application/json',
    'Authorization' => "OAuth oauth_token=#{access_token}"
  }
end

#make_path(path) ⇒ Object



36
37
38
39
# File 'lib/go_to_webinar/client.rb', line 36

def make_path(path)
  path.gsub!(':organizer_key:', organizer_key)
  "#{url}#{path}"
end

#post(path, data) ⇒ Object



24
25
26
# File 'lib/go_to_webinar/client.rb', line 24

def post(path, data)
  attempt { parse(RestClient.post(make_path(path), data, headers)) }
end

#put(path, data) ⇒ Object



28
29
30
# File 'lib/go_to_webinar/client.rb', line 28

def put(path, data)
  attempt { parse(RestClient.put(make_path(path), data, headers)) }
end