Class: StashCLI::Client
- Inherits:
-
Object
- Object
- StashCLI::Client
- Defined in:
- lib/stash_cli/client.rb
Constant Summary collapse
- BASE_API_URL =
'rest/api/1.0'
Instance Attribute Summary collapse
-
#resource ⇒ Object
readonly
Returns the value of attribute resource.
-
#server ⇒ Object
readonly
Returns the value of attribute server.
Instance Method Summary collapse
- #branches(project, slug) ⇒ Object
-
#initialize(server, auth_token) ⇒ Client
constructor
A new instance of Client.
- #pull_request(options = {}) ⇒ Object
- #repositories(project) ⇒ Object
- #users ⇒ Object
Constructor Details
#initialize(server, auth_token) ⇒ Client
14 15 16 17 18 19 20 21 22 23 |
# File 'lib/stash_cli/client.rb', line 14 def initialize(server, auth_token) @server = URI(server) @resource = RestClient::Resource.new( File.join(@server.to_s, BASE_API_URL), headers: { authorization: "Basic #{auth_token}", accept: :json, content_type: :json }) end |
Instance Attribute Details
#resource ⇒ Object (readonly)
Returns the value of attribute resource.
12 13 14 |
# File 'lib/stash_cli/client.rb', line 12 def resource @resource end |
#server ⇒ Object (readonly)
Returns the value of attribute server.
12 13 14 |
# File 'lib/stash_cli/client.rb', line 12 def server @server end |
Instance Method Details
#branches(project, slug) ⇒ Object
35 36 37 38 |
# File 'lib/stash_cli/client.rb', line 35 def branches(project, slug) response = resource["projects/#{project}/repos/#{slug}/branches?limit=1000"].get JSON.parse(response.body) end |
#pull_request(options = {}) ⇒ Object
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 |
# File 'lib/stash_cli/client.rb', line 40 def pull_request(={}) params = { title: [:title], fromRef: { id: "refs/heads/#{[:from_branch]}", repository: { slug: [:from_slug], project: { key: [:project] } } }, toRef: { id: "refs/heads/#{[:target_branch]}", repository: { slug: [:target_slug], project: { key: [:project] } } }, reviewers: [] } if [:reviewers].any? params[:reviewers] = [:reviewers].map do |name| { user: { name: name } } end end params[:description] = [:description] if [:description] path = "projects/#{[:project]}/repos/#{[:target_slug]}/pull-requests" response = resource[path].post(params.to_json) PullRequest.from_response(JSON.parse(response.body), server.to_s) end |
#repositories(project) ⇒ Object
30 31 32 33 |
# File 'lib/stash_cli/client.rb', line 30 def repositories(project) response = resource["projects/#{project}/repos?limit=1000"].get JSON.parse(response.body) end |
#users ⇒ Object
25 26 27 28 |
# File 'lib/stash_cli/client.rb', line 25 def users response = resource['users?limit=1000'].get JSON.parse(response.body)['values'] end |