Class: ClientSuccess::Connection

Inherits:
Object
  • Object
show all
Defined in:
lib/client_success/connection.rb

Defined Under Namespace

Classes: BadRequest, Error, Failed, NotFound, ParsingError, Unauthorised

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.authorised(access_token) ⇒ Object



16
17
18
# File 'lib/client_success/connection.rb', line 16

def authorised(access_token)
  new.tap { |conn| conn.access_token = access_token }
end

Instance Method Details

#access_tokenObject



28
29
30
# File 'lib/client_success/connection.rb', line 28

def access_token
  headers["Authorization"]
end

#access_token=(access_token) ⇒ Object



32
33
34
# File 'lib/client_success/connection.rb', line 32

def access_token=(access_token)
  headers["Authorization"] = access_token
end

#delete(path, headers = {}, &block) ⇒ Object



56
57
58
# File 'lib/client_success/connection.rb', line 56

def delete(path, headers = {}, &block)
  request { adapter.delete(path, headers, &block) }
end

#get(path, headers = {}, &block) ⇒ Object



36
37
38
# File 'lib/client_success/connection.rb', line 36

def get(path, headers = {}, &block)
  request { adapter.get(path, headers, &block) }
end

#head(path, headers = {}, &block) ⇒ Object

Raises:

  • (NotImplementedError)


40
41
42
# File 'lib/client_success/connection.rb', line 40

def head(path, headers = {}, &block)
  raise NotImplementedError
end

#loggerObject



21
22
23
24
25
26
# File 'lib/client_success/connection.rb', line 21

def logger
  # TODO: something better than this
  Logger.new(STDOUT).tap do |l|
    l.level = Logger::WARN
  end
end

#options(path, headers = {}, &block) ⇒ Object

Raises:

  • (NotImplementedError)


60
61
62
# File 'lib/client_success/connection.rb', line 60

def options(path, headers = {}, &block)
  raise NotImplementedError
end

#patch(path, body = nil, headers = {}, &block) ⇒ Object



52
53
54
# File 'lib/client_success/connection.rb', line 52

def patch(path, body = nil, headers = {}, &block)
  request { adapter.patch(path, body, headers, &block) }
end

#post(path, body = nil, headers = {}, &block) ⇒ Object



44
45
46
# File 'lib/client_success/connection.rb', line 44

def post(path, body = nil, headers = {}, &block)
  request { adapter.post(path, body, headers, &block) }
end

#put(path, body = nil, headers = {}, &block) ⇒ Object



48
49
50
# File 'lib/client_success/connection.rb', line 48

def put(path, body = nil, headers = {}, &block)
  request { adapter.put(path, body, headers, &block) }
end