Class: Githubris::API

Inherits:
Object
  • Object
show all
Includes:
Gist, HTTP, JSON, User
Defined in:
lib/githubris/api.rb

Defined Under Namespace

Modules: Gist, HTTP, JSON, User

Instance Method Summary collapse

Methods included from User

#get_authenticated_user, #get_user

Methods included from Gist

#delete_gist, #delete_gist_star, #get_gist, #get_gist_starred?, #get_public_gists, #get_user_gists, #get_user_starred_gists, #patch_gist, #post_gist, #put_gist_star

Constructor Details

#initializeAPI

Returns a new instance of API.



14
15
16
17
# File 'lib/githubris/api.rb', line 14

def initialize
  @target = Addressable::URI.new default_uri_options
  @options = {}
end

Instance Method Details

#authenticated?Boolean

Returns:

  • (Boolean)


38
39
40
41
42
# File 'lib/githubris/api.rb', line 38

def authenticated?
  get_authenticated_user
rescue Githubris::Error::RequiresAuthentication, Githubris::Error::BadCredentials
  nil
end

#basic_auth(login, password) ⇒ Object



27
28
29
30
31
32
# File 'lib/githubris/api.rb', line 27

def basic_auth , password
  @options[:basic_auth] = {
    :username => ,
    :password => password
  }
end

#default_uri_optionsObject



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

def default_uri_options
  {
    :scheme => 'https',
    :host => 'api.github.com',
    :query => ''
  }
end

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



48
49
50
51
52
# File 'lib/githubris/api.rb', line 48

def get(path, options={})
  set_request_path(path)
  @target.query_values = options
  dump_json(_get.parsed_response)
end

#get_data_from(path, options = {}) ⇒ Object



44
45
46
# File 'lib/githubris/api.rb', line 44

def get_data_from(path, options={})
  handle_request_data get(path, options)
end

#oauth(client_id, client_secret) ⇒ Object



34
35
36
# File 'lib/githubris/api.rb', line 34

def oauth(client_id, client_secret)
  Githubris::OAuth.new client_id, client_secret, self
end

#patch(path, params) ⇒ Object



73
74
75
76
# File 'lib/githubris/api.rb', line 73

def patch(path, params)
  set_request(path, params)
  dump_json(_patch.parsed_response)
end

#patch_data_to(path, params) ⇒ Object



69
70
71
# File 'lib/githubris/api.rb', line 69

def patch_data_to(path, params)
  handle_request_data patch(path, dump_json(params))
end

#post(path, params) ⇒ Object



64
65
66
67
# File 'lib/githubris/api.rb', line 64

def post(path, params)
  set_request(path, params)
  dump_json(_post.parsed_response)
end

#post_data_to(path, params) ⇒ Object



60
61
62
# File 'lib/githubris/api.rb', line 60

def post_data_to(path, params)
  handle_request_data post(path, dump_json(params))
end

#post_oauth_access_token(params) ⇒ Object



54
55
56
57
58
# File 'lib/githubris/api.rb', line 54

def post_oauth_access_token(params)
  @target.query += _post(oauth_access_token_url, :query => params)
  @options[:default_params] ||= {}
  @options[:default_params][:access_token] = @target.query_values['access_token']
end