Class: Octopi::Api
Included Modules
Singleton
This is the real API class
Attributes
Instance Attributes
format | [RW] | public |
Sets the attribute format. |
---|---|---|---|
login | [RW] | public |
Sets the attribute login. |
read_only | [RW] | public |
Sets the attribute read_only. |
token | [RW] | public |
Sets the attribute token. |
trace_level | [RW] | public |
Sets the attribute trace_level. |
Constants
- CONTENT_TYPE
- { 'yaml' => 'application/x-yaml', 'json' => 'application/json', 'xml' => 'application/sml' }
- MAX_RETRIES
- 10
- RETRYABLE_STATUS
- [403]
Public Visibility
Public Class Method Summary
api |
The API we’re using. |
---|---|
api=(value) |
set the API we’re using. |
authenticated |
Would be nice if cattr_accessor was available, oh well. |
authenticated=(value) |
We set this to true when the user has auth’d. |
Public Instance Method Summary
#commits(repo, opts = {}) | |
---|---|
#find(path, result_key, resource_id, klass = nil) | |
#find_all(path, result_key, query, klass = nil) | |
#get(path, params = {}, klass = nil, format = "yaml") | |
#get_raw(path, params, klass = nil) | |
#open_issue(user, repo, params) | |
#post(path, params = {}, klass = nil, format = "yaml") | |
#repository(name) #repo | |
#save(resource_path, data) | |
#user |
Public Class Method Details
api
public
api
The API we’re using
[View source]
54 55 56 |
# File 'lib/octopi/api.rb', line 54 def self.api @@api end |
api=
public
api=(value)
set the API we’re using
[View source]
59 60 61 |
# File 'lib/octopi/api.rb', line 59 def self.api=(value) @@api = value end |
authenticated
public
authenticated
Would be nice if cattr_accessor was available, oh well. We use this to check if we use the auth or anonymous api
[View source]
44 45 46 |
# File 'lib/octopi/api.rb', line 44 def self.authenticated @@authenticated end |
authenticated=
public
authenticated=(value)
We set this to true when the user has auth’d.
[View source]
49 50 51 |
# File 'lib/octopi/api.rb', line 49 def self.authenticated=(value) @@authenticated = value end |
Public Instance Method Details
commits
public
commits(repo, opts = {})
[View source]
87 88 89 90 |
# File 'lib/octopi/api.rb', line 87 def commits(repo,opts={}) branch = opts[:branch] || "master" commits = Commit.find_all(repo, branch, self) end |
find
public
find(path, result_key, resource_id, klass = nil)
[View source]
98 99 100 |
# File 'lib/octopi/api.rb', line 98 def find(path, result_key, resource_id, klass=nil) get(path, { :id => resource_id }, klass) end |
find_all
public
find_all(path, result_key, query, klass = nil)
[View source]
103 104 105 |
# File 'lib/octopi/api.rb', line 103 def find_all(path, result_key, query, klass=nil) get(path, { :query => query, :id => query }, klass)[result_key] end |
get
public
get(path, params = {}, klass = nil, format = "yaml")
[View source]
111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 |
# File 'lib/octopi/api.rb', line 111 def get(path, params = {}, klass=nil, format = "yaml") @@retries = 0 begin trace "GET [#{format}]", "/#{format}#{path}", params submit(path, params, klass, format) do |path, params, format| self.class.get "/#{format}#{path}" end rescue RetryableAPIError => e if @@retries < MAX_RETRIES $stderr.puts e. @@retries += 1 sleep 6 retry else raise APIError, "GitHub returned status #{e.code}, despite" + " repeating the request #{MAX_RETRIES} times. Giving up." end end end |
get_raw
public
get_raw(path, params, klass = nil)
[View source]
107 108 109 |
# File 'lib/octopi/api.rb', line 107 def get_raw(path, params, klass=nil) get(path, params, klass, 'plain') end |
open_issue
public
open_issue(user, repo, params)
[View source]
76 77 78 |
# File 'lib/octopi/api.rb', line 76 def open_issue(user, repo, params) Issue.open(user, repo, params, self) end |
post
public
post(path, params = {}, klass = nil, format = "yaml")
[View source]
131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 |
# File 'lib/octopi/api.rb', line 131 def post(path, params = {}, klass=nil, format = "yaml") @@retries = 0 begin trace "POST", "/#{format}#{path}", params submit(path, params, klass, format) do |path, params, format| resp = self.class.post "/#{format}#{path}", :body => params resp end rescue RetryableAPIError => e if @@retries < MAX_RETRIES $stderr.puts e. @@retries += 1 sleep 6 retry else raise APIError, "GitHub returned status #{e.code}, despite" + " repeating the request #{MAX_RETRIES} times. Giving up." end end end |
repository
public
repository(name)
Also known as: repo
[View source]
80 81 82 83 84 |
# File 'lib/octopi/api.rb', line 80 def repository(name) repo = Repository.find(user, name, self) repo.api = self repo end |
save
public
save(resource_path, data)
[View source]
92 93 94 95 96 |
# File 'lib/octopi/api.rb', line 92 def save(resource_path, data) traslate resource_path, data #still can't figure out on what format values are expected post("#{resource_path}", { :query => data }) end |
user
public
user
[View source]
70 71 72 73 74 |
# File 'lib/octopi/api.rb', line 70 def user user_data = get("/user/show/#{login}") raise "Unexpected response for user command" unless user_data and user_data['user'] User.new(user_data['user']) end |