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.



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

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.



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

def fizzy_url
  @fizzy_url
end

#passwordObject (readonly)

Returns the value of attribute password.



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

def password
  @password
end

#usernameObject (readonly)

Returns the value of attribute username.



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

def username
  @username
end

Instance Method Details

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



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

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



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

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



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

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