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_git_submodules ⇒ Object
- .use_git_submodules=(use_git_submodules) ⇒ Object
- .use_pivotal_tracker ⇒ Object
- .use_pivotal_tracker=(use_pivotal_tracker) ⇒ Object
Class Method Details
.base_options ⇒ Object
176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 |
# File 'lib/toolshed/client.rb', line 176 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
131 132 133 |
# File 'lib/toolshed/client.rb', line 131 def self.config_path ENV['TOOLSHED_CONFIG'] || '~/.toolshed' end |
.credentials_loaded? ⇒ Boolean
172 173 174 |
# File 'lib/toolshed/client.rb', line 172 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
102 103 104 |
# File 'lib/toolshed/client.rb', line 102 def self.default_pivotal_tracker_project_id @default_pivotal_tracker_project_id end |
.default_pivotal_tracker_project_id=(default_pivotal_tracker_project_id) ⇒ Object
106 107 108 |
# File 'lib/toolshed/client.rb', line 106 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
210 211 212 |
# File 'lib/toolshed/client.rb', line 210 def self.delete(path, = {}) request :delete, path, end |
.get(path, options = {}) ⇒ Object
198 199 200 |
# File 'lib/toolshed/client.rb', line 198 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
119 120 121 |
# File 'lib/toolshed/client.rb', line 119 def self.http_proxy @http_proxy end |
.http_proxy=(http_proxy) ⇒ Object
123 124 125 |
# File 'lib/toolshed/client.rb', line 123 def self.http_proxy=(http_proxy) @http_proxy = http_proxy end |
.load_credentials(path = config_path) ⇒ Object
135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 |
# File 'lib/toolshed/client.rb', line 135 def self.load_credentials(path = config_path) begin dir = Dir.pwd while File.(dir) != '/' do if (File.exists? "#{dir}/.toolshedrc") loaded_from_path = "#{dir}/.toolshedrc" break elsif (File.exists? "#{dir}/.toolshed") loaded_from_path = "#{dir}/.toolshed" warn "[DEPRECATION] `.toolshed` file is being deprecated. Please use a `.toolshedrc` file instead." break end dir = File.join dir, '..' end credentials = YAML.load_file(File.(loaded_from_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'] self.use_git_submodules ||= credentials['use_git_submodules'] @credentials_loaded = true puts "Credentials loaded from #{File.absolute_path(loaded_from_path)}" rescue => error puts "Error loading your credentials: #{error.message}" exit 1 end end |
.load_credentials_if_necessary ⇒ Object
127 128 129 |
# File 'lib/toolshed/client.rb', line 127 def self.load_credentials_if_necessary load_credentials unless credentials_loaded? end |
.pivotal_tracker_password ⇒ Object
94 95 96 |
# File 'lib/toolshed/client.rb', line 94 def self.pivotal_tracker_password @pivotal_tracker_password end |
.pivotal_tracker_password=(password) ⇒ Object
98 99 100 |
# File 'lib/toolshed/client.rb', line 98 def self.pivotal_tracker_password=(password) @pivotal_tracker_password = password end |
.pivotal_tracker_username ⇒ Object
pivotal tracker config
86 87 88 |
# File 'lib/toolshed/client.rb', line 86 def self.pivotal_tracker_username @pivotal_tracker_username end |
.pivotal_tracker_username=(username) ⇒ Object
90 91 92 |
# File 'lib/toolshed/client.rb', line 90 def self.pivotal_tracker_username=(username) @pivotal_tracker_username = username end |
.post(path, options = {}) ⇒ Object
202 203 204 |
# File 'lib/toolshed/client.rb', line 202 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
206 207 208 |
# File 'lib/toolshed/client.rb', line 206 def self.put(path, = {}) request :put, path, end |
.request(method, path, options) ⇒ Object
214 215 216 217 218 219 220 221 222 |
# File 'lib/toolshed/client.rb', line 214 def self.request(method, path, ) response = HTTParty.send(method, "#{base_uri}#{path}", .merge()) if response.code == 401 raise AuthenticationFailed end response end |
.use_git_submodules ⇒ Object
75 76 77 |
# File 'lib/toolshed/client.rb', line 75 def self.use_git_submodules @use_git_submodules end |
.use_git_submodules=(use_git_submodules) ⇒ Object
79 80 81 |
# File 'lib/toolshed/client.rb', line 79 def self.use_git_submodules=(use_git_submodules) @use_git_submodules = use_git_submodules end |
.use_pivotal_tracker ⇒ Object
110 111 112 |
# File 'lib/toolshed/client.rb', line 110 def self.use_pivotal_tracker @use_pivotal_tracker end |
.use_pivotal_tracker=(use_pivotal_tracker) ⇒ Object
114 115 116 |
# File 'lib/toolshed/client.rb', line 114 def self.use_pivotal_tracker=(use_pivotal_tracker) @use_pivotal_tracker = use_pivotal_tracker end |