Class: Toolshed::Client
- Inherits:
-
Object
- Object
- Toolshed::Client
- Defined in:
- lib/toolshed/client.rb
Constant Summary collapse
- GITHUB_BASE_API_URL =
"https://api.github.com/"
- PIVOTAL_TRACKER_BASE_API_URL =
"https://www.pivotaltracker.com/services/v5/"
Class Method Summary collapse
- .base_options ⇒ Object
- .branched_from_remote_name ⇒ Object
- .branched_from_remote_name=(branched_from_remote_name) ⇒ Object
- .branched_from_repo_name ⇒ Object
- .branched_from_repo_name=(branched_from_repo_name) ⇒ Object
- .branched_from_user ⇒ Object
- .branched_from_user=(branched_from_user) ⇒ Object
- .config_path ⇒ Object
- .credentials_loaded? ⇒ Boolean
- .debug=(debug) ⇒ Object
- .debug? ⇒ Boolean
- .default_pivotal_tracker_project_id ⇒ Object
- .default_pivotal_tracker_project_id=(default_pivotal_tracker_project_id) ⇒ Object
- .delete(path, options = {}) ⇒ Object
- .get(path, options = {}) ⇒ Object
- .github_password ⇒ Object
- .github_password=(password) ⇒ Object
-
.github_username ⇒ Object
github config settings.
- .github_username=(username) ⇒ Object
- .http_proxy ⇒ Object
- .http_proxy=(http_proxy) ⇒ Object
- .load_credentials(path = config_path) ⇒ Object
- .load_credentials_if_necessary ⇒ Object
- .pivotal_tracker_password ⇒ Object
- .pivotal_tracker_password=(password) ⇒ Object
-
.pivotal_tracker_username ⇒ Object
pivotal tracker config.
- .pivotal_tracker_username=(username) ⇒ Object
- .post(path, options = {}) ⇒ Object
- .push_from_user ⇒ Object
- .push_from_user=(push_from_user) ⇒ Object
- .push_to_myself ⇒ Object
- .push_to_myself=(push_to_myself) ⇒ Object
- .put(path, options = {}) ⇒ Object
- .request(method, path, options) ⇒ Object
- .use_pivotal_tracker ⇒ Object
- .use_pivotal_tracker=(use_pivotal_tracker) ⇒ Object
Class Method Details
.base_options ⇒ Object
153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 |
# File 'lib/toolshed/client.rb', line 153 def self. = { :format => :json, :headers => { 'Accept' => 'application/json', 'User-Agent' => "toolshed-ruby/#{Toolshed::VERSION}" }, } if http_proxy .merge!( :http_proxyaddr => self.http_proxy[:addr], :http_proxyport => self.http_proxy[:port] ) end if password [:basic_auth] = { :username => username, :password => password } else raise Error, 'A password is required for all API requests.' end end |
.branched_from_remote_name ⇒ Object
35 36 37 |
# File 'lib/toolshed/client.rb', line 35 def self.branched_from_remote_name @branched_from_remote_name end |
.branched_from_remote_name=(branched_from_remote_name) ⇒ Object
39 40 41 |
# File 'lib/toolshed/client.rb', line 39 def self.branched_from_remote_name=(branched_from_remote_name) @branched_from_remote_name = branched_from_remote_name end |
.branched_from_repo_name ⇒ Object
51 52 53 |
# File 'lib/toolshed/client.rb', line 51 def self.branched_from_repo_name @branched_from_repo_name end |
.branched_from_repo_name=(branched_from_repo_name) ⇒ Object
55 56 57 |
# File 'lib/toolshed/client.rb', line 55 def self.branched_from_repo_name=(branched_from_repo_name) @branched_from_repo_name = branched_from_repo_name end |
.branched_from_user ⇒ Object
43 44 45 |
# File 'lib/toolshed/client.rb', line 43 def self.branched_from_user @branched_from_user end |
.branched_from_user=(branched_from_user) ⇒ Object
47 48 49 |
# File 'lib/toolshed/client.rb', line 47 def self.branched_from_user=(branched_from_user) @branched_from_user = branched_from_user end |
.config_path ⇒ Object
123 124 125 |
# File 'lib/toolshed/client.rb', line 123 def self.config_path ENV['TOOLSHED_CONFIG'] || '~/.toolshed' end |
.credentials_loaded? ⇒ Boolean
149 150 151 |
# File 'lib/toolshed/client.rb', line 149 def self.credentials_loaded? (@credentials_loaded ||= false) or (github_username and github_password and pivotal_tracker_username and pivotal_tracker_password) end |
.debug=(debug) ⇒ Object
13 14 15 |
# File 'lib/toolshed/client.rb', line 13 def self.debug=(debug) @debug = debug end |
.debug? ⇒ Boolean
9 10 11 |
# File 'lib/toolshed/client.rb', line 9 def self.debug? @debug end |
.default_pivotal_tracker_project_id ⇒ Object
94 95 96 |
# File 'lib/toolshed/client.rb', line 94 def self.default_pivotal_tracker_project_id @default_pivotal_tracker_project_id end |
.default_pivotal_tracker_project_id=(default_pivotal_tracker_project_id) ⇒ Object
98 99 100 |
# File 'lib/toolshed/client.rb', line 98 def self.default_pivotal_tracker_project_id=(default_pivotal_tracker_project_id) @default_pivotal_tracker_project_id = default_pivotal_tracker_project_id end |
.delete(path, options = {}) ⇒ Object
187 188 189 |
# File 'lib/toolshed/client.rb', line 187 def self.delete(path, = {}) request :delete, path, end |
.get(path, options = {}) ⇒ Object
175 176 177 |
# File 'lib/toolshed/client.rb', line 175 def self.get(path, = {}) request :get, path, end |
.github_password ⇒ Object
27 28 29 |
# File 'lib/toolshed/client.rb', line 27 def self.github_password @github_password end |
.github_password=(password) ⇒ Object
31 32 33 |
# File 'lib/toolshed/client.rb', line 31 def self.github_password=(password) @github_password = password end |
.github_username ⇒ Object
github config settings
19 20 21 |
# File 'lib/toolshed/client.rb', line 19 def self.github_username @github_username end |
.github_username=(username) ⇒ Object
23 24 25 |
# File 'lib/toolshed/client.rb', line 23 def self.github_username=(username) @github_username = username end |
.http_proxy ⇒ Object
111 112 113 |
# File 'lib/toolshed/client.rb', line 111 def self.http_proxy @http_proxy end |
.http_proxy=(http_proxy) ⇒ Object
115 116 117 |
# File 'lib/toolshed/client.rb', line 115 def self.http_proxy=(http_proxy) @http_proxy = http_proxy end |
.load_credentials(path = config_path) ⇒ Object
127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 |
# File 'lib/toolshed/client.rb', line 127 def self.load_credentials(path = config_path) begin credentials = YAML.load_file(File.(path)) self.github_username ||= credentials['github_username'] self.github_password ||= credentials['github_password'] self.pivotal_tracker_username ||= credentials['pivotal_tracker_username'] self.pivotal_tracker_password ||= credentials['pivotal_tracker_password'] self.default_pivotal_tracker_project_id ||= credentials['default_pivotal_tracker_project_id'] self.branched_from_remote_name ||= credentials['branched_from_remote_name'] self.branched_from_user ||= credentials['branched_from_user'] self.branched_from_repo_name ||= credentials['branched_from_repo_name'] self.push_from_user ||= credentials['push_from_user'] self.push_to_myself ||= credentials['push_to_myself'] self.use_pivotal_tracker ||= credentials['use_pivotal_tracker'] @credentials_loaded = true puts "Credentials loaded from #{path}" rescue => error puts "Error loading your credentials: #{error.}" exit 1 end end |
.load_credentials_if_necessary ⇒ Object
119 120 121 |
# File 'lib/toolshed/client.rb', line 119 def self.load_credentials_if_necessary load_credentials unless credentials_loaded? end |
.pivotal_tracker_password ⇒ Object
86 87 88 |
# File 'lib/toolshed/client.rb', line 86 def self.pivotal_tracker_password @pivotal_tracker_password end |
.pivotal_tracker_password=(password) ⇒ Object
90 91 92 |
# File 'lib/toolshed/client.rb', line 90 def self.pivotal_tracker_password=(password) @pivotal_tracker_password = password end |
.pivotal_tracker_username ⇒ Object
pivotal tracker config
78 79 80 |
# File 'lib/toolshed/client.rb', line 78 def self.pivotal_tracker_username @pivotal_tracker_username end |
.pivotal_tracker_username=(username) ⇒ Object
82 83 84 |
# File 'lib/toolshed/client.rb', line 82 def self.pivotal_tracker_username=(username) @pivotal_tracker_username = username end |
.post(path, options = {}) ⇒ Object
179 180 181 |
# File 'lib/toolshed/client.rb', line 179 def self.post(path, = {}) request :post, path, end |
.push_from_user ⇒ Object
59 60 61 |
# File 'lib/toolshed/client.rb', line 59 def self.push_from_user @push_from_user end |
.push_from_user=(push_from_user) ⇒ Object
63 64 65 |
# File 'lib/toolshed/client.rb', line 63 def self.push_from_user=(push_from_user) @push_from_user = push_from_user end |
.push_to_myself ⇒ Object
67 68 69 |
# File 'lib/toolshed/client.rb', line 67 def self.push_to_myself @push_to_myself end |
.push_to_myself=(push_to_myself) ⇒ Object
71 72 73 |
# File 'lib/toolshed/client.rb', line 71 def self.push_to_myself=(push_to_myself) @push_to_myself = push_to_myself end |
.put(path, options = {}) ⇒ Object
183 184 185 |
# File 'lib/toolshed/client.rb', line 183 def self.put(path, = {}) request :put, path, end |
.request(method, path, options) ⇒ Object
191 192 193 194 195 196 197 198 199 |
# File 'lib/toolshed/client.rb', line 191 def self.request(method, path, ) response = HTTParty.send(method, "#{base_uri}#{path}", .merge()) if response.code == 401 raise AuthenticationFailed end response end |
.use_pivotal_tracker ⇒ Object
102 103 104 |
# File 'lib/toolshed/client.rb', line 102 def self.use_pivotal_tracker @use_pivotal_tracker end |
.use_pivotal_tracker=(use_pivotal_tracker) ⇒ Object
106 107 108 |
# File 'lib/toolshed/client.rb', line 106 def self.use_pivotal_tracker=(use_pivotal_tracker) @use_pivotal_tracker = use_pivotal_tracker end |