Class: Stash::Client
- Inherits:
-
Object
- Object
- Stash::Client
- Defined in:
- lib/stash/client.rb,
lib/stash/client/version.rb
Constant Summary collapse
- VERSION =
"0.0.7"
Instance Attribute Summary collapse
-
#url ⇒ Object
readonly
Returns the value of attribute url.
Instance Method Summary collapse
- #changes_for(repo, sha, opts = {}) ⇒ Object
- #commits_for(repo, opts = {}) ⇒ Object
-
#initialize(opts = {}) ⇒ Client
constructor
A new instance of Client.
- #project_named(name) ⇒ Object
- #projects ⇒ Object
- #repositories ⇒ Object
- #repository_named(name) ⇒ Object
Constructor Details
#initialize(opts = {}) ⇒ Client
Returns a new instance of Client.
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/stash/client.rb', line 11 def initialize(opts = {}) if opts[:host] && opts[:scheme] @url = Addressable::URI.parse(opts[:scheme] + '://' + opts[:host] + '/rest/api/1.0/') elsif opts[:host] @url = Addressable::URI.parse('http://' + opts[:host] + '/rest/api/1.0/') elsif opts[:url] @url = Addressable::URI.parse(opts[:url]) elsif opts[:uri] && opts[:uri].kind_of?(Addressable::URI) @url = opts[:uri] else raise ArgumentError, "must provie :url or :host" end @url.userinfo = opts[:credentials] if opts[:credentials] end |
Instance Attribute Details
#url ⇒ Object (readonly)
Returns the value of attribute url.
9 10 11 |
# File 'lib/stash/client.rb', line 9 def url @url end |
Instance Method Details
#changes_for(repo, sha, opts = {}) ⇒ Object
70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 |
# File 'lib/stash/client.rb', line 70 def changes_for(repo, sha, opts = {}) path = remove_leading_slash repo.fetch('link').fetch('url').sub('browse', 'changes') uri = @url.join(path) query_values = { 'until' => sha } query_values['since'] = opts[:parent] if opts[:parent] query_values['limit'] = opts[:limit] if opts[:limit] uri.query_values = query_values if query_values['limit'] fetch(uri).fetch('values') else fetch_all(uri) end end |
#commits_for(repo, opts = {}) ⇒ Object
46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 |
# File 'lib/stash/client.rb', line 46 def commits_for(repo, opts = {}) query_values = {} path = remove_leading_slash repo.fetch('link').fetch('url').sub('browse', 'commits') uri = @url.join(path) query_values['since'] = opts[:since] if opts[:since] query_values['until'] = opts[:until] if opts[:until] query_values['limit'] = Integer(opts[:limit]) if opts[:limit] if query_values.empty? # default limit to 100 commits query_values['limit'] = 100 end uri.query_values = query_values if query_values['limit'] && query_values['limit'] < 100 fetch(uri).fetch('values') else fetch_all(uri) end end |
#project_named(name) ⇒ Object
38 39 40 |
# File 'lib/stash/client.rb', line 38 def project_named(name) projects.find { |e| e['name'] == name } end |
#projects ⇒ Object
27 28 29 |
# File 'lib/stash/client.rb', line 27 def projects fetch_all @url.join('projects') end |
#repositories ⇒ Object
31 32 33 34 35 36 |
# File 'lib/stash/client.rb', line 31 def repositories projects.flat_map do |project| relative_project_path = project.fetch('link').fetch('url') + '/repos' fetch_all @url.join(remove_leading_slash(relative_project_path)) end end |
#repository_named(name) ⇒ Object
42 43 44 |
# File 'lib/stash/client.rb', line 42 def repository_named(name) repositories.find { |e| e['name'] == name } end |