Module: Hyperkit::Connection

Included in:
Client
Defined in:
lib/hyperkit/connection.rb

Overview

Network layer for API clients.

Constant Summary collapse

CONVENIENCE_HEADERS =

Header keys that can be passed in options hash to #get,#head

Set.new([:accept, :content_type])

Instance Method Summary collapse

Instance Method Details

#agentSawyer::Agent

Hypermedia agent for the GitHub API


89
90
91
92
93
94
95
# File 'lib/hyperkit/connection.rb', line 89

def agent
  @agent ||= Sawyer::Agent.new(endpoint, sawyer_options) do |http|
    http.headers[:accept] = default_media_type
    http.headers[:content_type] = "application/json"
    http.headers[:user_agent] = user_agent
  end
end

#delete(url, options = {}) ⇒ Sawyer::Resource

Make a HTTP DELETE request


73
74
75
# File 'lib/hyperkit/connection.rb', line 73

def delete(url, options = {})
  request :delete, url, options
end

#get(url, options = {}) ⇒ Sawyer::Resource

Make a HTTP GET request


37
38
39
# File 'lib/hyperkit/connection.rb', line 37

def get(url, options = {})
  request :get, url, parse_query_and_convenience_headers(options)
end

#head(url, options = {}) ⇒ Sawyer::Resource

Make a HTTP HEAD request


82
83
84
# File 'lib/hyperkit/connection.rb', line 82

def head(url, options = {})
  request :head, url, parse_query_and_convenience_headers(options)
end

#last_responseSawyer::Response

Response for last HTTP request


107
108
109
# File 'lib/hyperkit/connection.rb', line 107

def last_response
  @last_response if defined? @last_response
end

#patch(url, options = {}) ⇒ Sawyer::Resource

Make a HTTP PATCH request


64
65
66
# File 'lib/hyperkit/connection.rb', line 64

def patch(url, options = {})
  request :patch, url, options
end

#post(url, options = {}) ⇒ Sawyer::Resource

Make a HTTP POST request


46
47
48
# File 'lib/hyperkit/connection.rb', line 46

def post(url, options = {})
  request :post, url, options
end

#put(url, options = {}) ⇒ Sawyer::Resource

Make a HTTP PUT request


55
56
57
# File 'lib/hyperkit/connection.rb', line 55

def put(url, options = {})
  request :put, url, options
end

#rootSawyer::Resource

Fetch the root resource for the API


100
101
102
# File 'lib/hyperkit/connection.rb', line 100

def root
  get "/"
end