Class: Fizzy::Api::Sessions::BasicAuthSession

Inherits:
Object
  • Object
show all
Defined in:
lib/fizzy/api/sessions/basic_auth_session.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(fizzy_url: ENV['FIZZY_URL'], username: ENV['FIZZY_BASICAUTH_ID'], password: ENV['FIZZY_BASICAUTH_SECRET']) ⇒ BasicAuthSession

Returns a new instance of BasicAuthSession.



9
10
11
12
13
14
15
# File 'lib/fizzy/api/sessions/basic_auth_session.rb', line 9

def initialize(fizzy_url: ENV['FIZZY_URL'],
               username: ENV['FIZZY_BASICAUTH_ID'],
               password: ENV['FIZZY_BASICAUTH_SECRET'])
  @fizzy_url = fizzy_url
  @username = username
  @password = password
end

Instance Attribute Details

#fizzy_urlObject (readonly)

Returns the value of attribute fizzy_url.



5
6
7
# File 'lib/fizzy/api/sessions/basic_auth_session.rb', line 5

def fizzy_url
  @fizzy_url
end

#passwordObject (readonly)

Returns the value of attribute password.



7
8
9
# File 'lib/fizzy/api/sessions/basic_auth_session.rb', line 7

def password
  @password
end

#usernameObject (readonly)

Returns the value of attribute username.



6
7
8
# File 'lib/fizzy/api/sessions/basic_auth_session.rb', line 6

def username
  @username
end

Instance Method Details

#delete(path, params = {}) ⇒ Object



34
35
36
37
38
39
40
# File 'lib/fizzy/api/sessions/basic_auth_session.rb', line 34

def delete(path, params = {})
  perform_request_or_fail do
    HTTParty.delete(full_url_for(path),
                    query: params,
                    basic_auth: basic_auth)
  end
end

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



17
18
19
20
21
22
23
# File 'lib/fizzy/api/sessions/basic_auth_session.rb', line 17

def get(path, params = {})
  perform_request_or_fail do
    HTTParty.get(full_url_for(path),
                 query: params,
                 basic_auth: basic_auth)
  end
end

#post(path, params = {}) ⇒ Object



25
26
27
28
29
30
31
32
# File 'lib/fizzy/api/sessions/basic_auth_session.rb', line 25

def post(path, params = {})
  perform_request_or_fail do
    HTTParty.post(full_url_for(path),
                  headers: { 'Content-Type' => 'application/json' },
                  body: params.to_json,
                  basic_auth: basic_auth)
  end
end