stash_api 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +9 -0
- data/.travis.yml +4 -0
- data/Gemfile +4 -0
- data/LICENSE +22 -0
- data/README.md +42 -0
- data/Rakefile +10 -0
- data/bin/console +11 -0
- data/bin/setup +7 -0
- data/lib/http/http.rb +40 -0
- data/lib/stash_api/base.rb +15 -0
- data/lib/stash_api/comment.rb +12 -0
- data/lib/stash_api/core.rb +11 -0
- data/lib/stash_api/options.rb +38 -0
- data/lib/stash_api/project.rb +13 -0
- data/lib/stash_api/pull_request.rb +13 -0
- data/lib/stash_api/repo.rb +13 -0
- data/lib/stash_api/resource.rb +86 -0
- data/lib/stash_api/version.rb +3 -0
- data/lib/stash_api.rb +11 -0
- data/stash_api.gemspec +26 -0
- metadata +120 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: ac36a7380c0a32c9849de48e57a8f1215b065742
|
4
|
+
data.tar.gz: a536d5ea4ae443344691f49736fccc7e3542bf24
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: bc3589b49f7b3621219eaa38edfcd7dd3465a970bf2cab3306be9e27f07cfa75f6f749568d6127672da2b1119d22b626d93508b514fd203a137238d10038519e
|
7
|
+
data.tar.gz: f33106c04f3419d5777eec32f67f42288358af336dda3811c6e0503d945edb0c71b1529d0385bfb2a225fd894e1c1edec1ee220123cbb4fb4577138378a69200
|
data/.gitignore
ADDED
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2015 Zachary Chai
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
13
|
+
copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
21
|
+
SOFTWARE.
|
22
|
+
|
data/README.md
ADDED
@@ -0,0 +1,42 @@
|
|
1
|
+
# StashAPI
|
2
|
+
|
3
|
+
Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/stash_api`. To experiment with that code, run `bin/console` for an interactive prompt.
|
4
|
+
|
5
|
+
TODO: Delete this and the text above, and describe your gem
|
6
|
+
|
7
|
+
## Installation
|
8
|
+
|
9
|
+
Add this line to your application's Gemfile:
|
10
|
+
|
11
|
+
```ruby
|
12
|
+
gem 'stash_api'
|
13
|
+
```
|
14
|
+
|
15
|
+
And then execute:
|
16
|
+
|
17
|
+
$ bundle
|
18
|
+
|
19
|
+
Or install it yourself as:
|
20
|
+
|
21
|
+
$ gem install stash_api
|
22
|
+
|
23
|
+
## Usage
|
24
|
+
|
25
|
+
TODO: Write usage instructions here
|
26
|
+
|
27
|
+
## Development
|
28
|
+
|
29
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment. Run `bundle exec stash_api` to use the gem in this directory, ignoring other installed copies of this gem.
|
30
|
+
|
31
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
32
|
+
|
33
|
+
## Contributing
|
34
|
+
|
35
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/stash_api. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](contributor-covenant.org) code of conduct.
|
36
|
+
|
37
|
+
|
38
|
+
## License
|
39
|
+
|
40
|
+
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
|
41
|
+
|
42
|
+
|
data/Rakefile
ADDED
data/bin/console
ADDED
data/bin/setup
ADDED
data/lib/http/http.rb
ADDED
@@ -0,0 +1,40 @@
|
|
1
|
+
require 'httparty'
|
2
|
+
|
3
|
+
module HTTP
|
4
|
+
|
5
|
+
class Basement
|
6
|
+
include HTTParty
|
7
|
+
end
|
8
|
+
|
9
|
+
class Client
|
10
|
+
class << self
|
11
|
+
|
12
|
+
def base_uri=(value)
|
13
|
+
Basement.base_uri value
|
14
|
+
end
|
15
|
+
|
16
|
+
def get(path, options = {})
|
17
|
+
Basement.get(path, options);
|
18
|
+
end
|
19
|
+
|
20
|
+
def post(path, options = {})
|
21
|
+
Basement.post(path, options);
|
22
|
+
end
|
23
|
+
|
24
|
+
def base_uri
|
25
|
+
Basement.default_options[:base_uri].sub 'http://', ''
|
26
|
+
end
|
27
|
+
|
28
|
+
def basic_auth(u, v)
|
29
|
+
Basement.basic_auth u, v
|
30
|
+
end
|
31
|
+
|
32
|
+
def options
|
33
|
+
Basement.default_options
|
34
|
+
end
|
35
|
+
|
36
|
+
# force httparty to add the 'http://' to base uri
|
37
|
+
base_uri = ''
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
@@ -0,0 +1,38 @@
|
|
1
|
+
module StashAPI
|
2
|
+
class Options
|
3
|
+
@@default_options = {}
|
4
|
+
|
5
|
+
def self.options
|
6
|
+
@@default_options
|
7
|
+
end
|
8
|
+
|
9
|
+
def self.option(key, value = nil)
|
10
|
+
return @@default_options[key] unless value
|
11
|
+
@@default_options[key] = value
|
12
|
+
|
13
|
+
if key == :domain
|
14
|
+
build_base_uri
|
15
|
+
end
|
16
|
+
|
17
|
+
value
|
18
|
+
end
|
19
|
+
|
20
|
+
def self.reset_defaults
|
21
|
+
@@default_options = {}
|
22
|
+
build_base_uri # reset the base_uri
|
23
|
+
end
|
24
|
+
|
25
|
+
private
|
26
|
+
|
27
|
+
def self.build_base_uri
|
28
|
+
if @@default_options[:domain].nil?
|
29
|
+
HTTP::Client.base_uri = ''
|
30
|
+
else
|
31
|
+
HTTP::Client.base_uri = "#{@@default_options[:domain]}/rest"
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
# set any defaults
|
36
|
+
reset_defaults
|
37
|
+
end
|
38
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
module StashAPI
|
2
|
+
class PullRequest < Resource
|
3
|
+
class << self
|
4
|
+
@@position = 3
|
5
|
+
|
6
|
+
def comments(id = nil)
|
7
|
+
raise_resource_key_missing if resource_id(@@position - 1) == nil
|
8
|
+
add_resource_to_chain @@position, 'comments', id
|
9
|
+
Comment
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
module StashAPI
|
2
|
+
class Repo < Resource
|
3
|
+
class << self
|
4
|
+
@@position = 2
|
5
|
+
|
6
|
+
def pull_requests(id = nil)
|
7
|
+
raise_resource_key_missing if resource_id(@@position - 1) == nil
|
8
|
+
add_resource_to_chain @@position, 'pull-requests', id
|
9
|
+
PullRequest
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
@@ -0,0 +1,86 @@
|
|
1
|
+
module StashAPI
|
2
|
+
class Resource
|
3
|
+
@@resources = []
|
4
|
+
@@resource_ids = []
|
5
|
+
|
6
|
+
def self.fetch(query = {})
|
7
|
+
options = {}
|
8
|
+
options[:query] = query
|
9
|
+
|
10
|
+
response = HTTP::Client.get resource_path, options
|
11
|
+
reset_resource_chain
|
12
|
+
|
13
|
+
if response.code == 200
|
14
|
+
response.parsed_response
|
15
|
+
else
|
16
|
+
response.code
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
def self.fetch_all(query = {})
|
21
|
+
options = {}
|
22
|
+
|
23
|
+
query[:limit] = 1000
|
24
|
+
query[:start] = 0
|
25
|
+
options[:query] = query
|
26
|
+
|
27
|
+
results = []
|
28
|
+
|
29
|
+
begin
|
30
|
+
response = HTTP::Client.get(resource_path, options)
|
31
|
+
|
32
|
+
if response.code == 200
|
33
|
+
response = response.parsed_response
|
34
|
+
results.concat response['values']
|
35
|
+
options[:query][:start] = response['start'] + response['limit']
|
36
|
+
else
|
37
|
+
results == response
|
38
|
+
end
|
39
|
+
end while !response['isLastPage']
|
40
|
+
results
|
41
|
+
end
|
42
|
+
|
43
|
+
def self.create_resource(payload, options = {})
|
44
|
+
|
45
|
+
options[:body] = payload.to_json
|
46
|
+
options[:headers] = {'Content-Type' => 'application/json'}
|
47
|
+
|
48
|
+
response = HTTP::Client.post resource_path, options
|
49
|
+
|
50
|
+
response
|
51
|
+
end
|
52
|
+
|
53
|
+
def self.resource_path
|
54
|
+
path = '/api/1.0'
|
55
|
+
for i in 0..@@resources.size
|
56
|
+
path << "/#{@@resources[i]}" if @@resources[i]
|
57
|
+
path << "/#{@@resource_ids[i]}" if @@resource_ids[i]
|
58
|
+
end
|
59
|
+
path
|
60
|
+
end
|
61
|
+
|
62
|
+
def self.add_resource_to_chain(index, resource, key = nil)
|
63
|
+
@@resources[index] = "#{resource}"
|
64
|
+
@@resource_ids[index] = key
|
65
|
+
end
|
66
|
+
|
67
|
+
def self.reset_resource_chain
|
68
|
+
@@resources = []
|
69
|
+
@@resource_ids = []
|
70
|
+
end
|
71
|
+
|
72
|
+
def self.resource(pos)
|
73
|
+
@@resources[pos]
|
74
|
+
end
|
75
|
+
|
76
|
+
def self.resource_id(pos)
|
77
|
+
@@resource_ids[pos]
|
78
|
+
end
|
79
|
+
|
80
|
+
def self.raise_resource_key_missing
|
81
|
+
raise 'previous resource has no key to allow chaining'
|
82
|
+
end
|
83
|
+
|
84
|
+
reset_resource_chain
|
85
|
+
end
|
86
|
+
end
|
data/lib/stash_api.rb
ADDED
@@ -0,0 +1,11 @@
|
|
1
|
+
require 'http/http'
|
2
|
+
|
3
|
+
require 'stash_api/version'
|
4
|
+
require 'stash_api/options'
|
5
|
+
require 'stash_api/base'
|
6
|
+
require 'stash_api/resource'
|
7
|
+
require 'stash_api/core'
|
8
|
+
require 'stash_api/project'
|
9
|
+
require 'stash_api/repo'
|
10
|
+
require 'stash_api/pull_request'
|
11
|
+
require 'stash_api/comment'
|
data/stash_api.gemspec
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'stash_api/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "stash_api"
|
8
|
+
spec.version = StashAPI::VERSION
|
9
|
+
spec.authors = ["Zachary Chai"]
|
10
|
+
spec.email = ["zachary.chai@outlook.com"]
|
11
|
+
spec.summary = "Atlassian Stash API client"
|
12
|
+
spec.description = "A client for interacting with Atlassian Stash API"
|
13
|
+
spec.license = "MIT"
|
14
|
+
|
15
|
+
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
16
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
17
|
+
spec.require_paths = ["lib"]
|
18
|
+
|
19
|
+
spec.required_ruby_version = '>= 2.2.0'
|
20
|
+
|
21
|
+
spec.add_dependency 'httparty', '~> 0.13.2'
|
22
|
+
|
23
|
+
spec.add_development_dependency "bundler", "~> 1.10"
|
24
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
25
|
+
spec.add_development_dependency "minitest"
|
26
|
+
end
|
metadata
ADDED
@@ -0,0 +1,120 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: stash_api
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Zachary Chai
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2015-07-12 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: httparty
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 0.13.2
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 0.13.2
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: bundler
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '1.10'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '1.10'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rake
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '10.0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '10.0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: minitest
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
description: A client for interacting with Atlassian Stash API
|
70
|
+
email:
|
71
|
+
- zachary.chai@outlook.com
|
72
|
+
executables: []
|
73
|
+
extensions: []
|
74
|
+
extra_rdoc_files: []
|
75
|
+
files:
|
76
|
+
- ".gitignore"
|
77
|
+
- ".travis.yml"
|
78
|
+
- Gemfile
|
79
|
+
- LICENSE
|
80
|
+
- README.md
|
81
|
+
- Rakefile
|
82
|
+
- bin/console
|
83
|
+
- bin/setup
|
84
|
+
- lib/http/http.rb
|
85
|
+
- lib/stash_api.rb
|
86
|
+
- lib/stash_api/base.rb
|
87
|
+
- lib/stash_api/comment.rb
|
88
|
+
- lib/stash_api/core.rb
|
89
|
+
- lib/stash_api/options.rb
|
90
|
+
- lib/stash_api/project.rb
|
91
|
+
- lib/stash_api/pull_request.rb
|
92
|
+
- lib/stash_api/repo.rb
|
93
|
+
- lib/stash_api/resource.rb
|
94
|
+
- lib/stash_api/version.rb
|
95
|
+
- stash_api.gemspec
|
96
|
+
homepage:
|
97
|
+
licenses:
|
98
|
+
- MIT
|
99
|
+
metadata: {}
|
100
|
+
post_install_message:
|
101
|
+
rdoc_options: []
|
102
|
+
require_paths:
|
103
|
+
- lib
|
104
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
105
|
+
requirements:
|
106
|
+
- - ">="
|
107
|
+
- !ruby/object:Gem::Version
|
108
|
+
version: 2.2.0
|
109
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
110
|
+
requirements:
|
111
|
+
- - ">="
|
112
|
+
- !ruby/object:Gem::Version
|
113
|
+
version: '0'
|
114
|
+
requirements: []
|
115
|
+
rubyforge_project:
|
116
|
+
rubygems_version: 2.4.8
|
117
|
+
signing_key:
|
118
|
+
specification_version: 4
|
119
|
+
summary: Atlassian Stash API client
|
120
|
+
test_files: []
|