bintray-client-ruby 0.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 1edd677b1c112906de67ab879eac547e0bbb7561
4
+ data.tar.gz: 28a34206c074b807bd39119062c469030a5a388d
5
+ SHA512:
6
+ metadata.gz: 682b5f715713ba55b1f615c7ec4a0ef0280069f11cb22c19dba86a0683ae26a60110e6933ac9e39551c5e4358b618fcd3358371a949eb1f246f60d52676a5c73
7
+ data.tar.gz: f0145b3f15c25d26b8531a5b9c0241fa246e9f7eba19c2cf5184b3ae03911d8b02ce51c2c4e9d741339acfa2d27f62e6b61355642098976bef1fae421f271ba2
data/.gitignore ADDED
@@ -0,0 +1,9 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --color
data/.travis.yml ADDED
@@ -0,0 +1,6 @@
1
+ sudo: false
2
+ language: ruby
3
+ rvm:
4
+ - 2.3.0
5
+ - jruby
6
+ before_install: gem install bundler -v 1.12.5
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in bintray-client-ruby.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2016 John Faucett
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
13
+ all 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
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,41 @@
1
+ # Bintray::Client::Ruby
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/bintray/client/ruby`. 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 'bintray-client-ruby'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ $ bundle
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install bintray-client-ruby
22
+
23
+ ## Usage
24
+
25
+ see the examples folder
26
+
27
+ ## Development
28
+
29
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
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]/bintray-client-ruby. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://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
+
data/Rakefile ADDED
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
data/bin/console ADDED
@@ -0,0 +1,21 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "bintray/client/ruby"
5
+ require 'pry'
6
+ require 'stringio'
7
+ require 'logger'
8
+
9
+ buf = StringIO.new
10
+ logger = Logger.new(buf)
11
+ logger.level = Logger::DEBUG
12
+
13
+ $client = Bintray::Client::Ruby.http_client({
14
+ username: ENV['BINTRAY_USER'],
15
+ password: ENV['BINTRAY_API_KEY'],
16
+ debug: true,
17
+ logger: logger,
18
+ log_buffer: buf
19
+ })
20
+
21
+ Pry::CLI.parse_options
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,31 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'bintray/client/ruby/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "bintray-client-ruby"
8
+ spec.version = Bintray::Client::Ruby.version
9
+ spec.authors = ["John Faucett"]
10
+ spec.email = ["jwaterfaucett@gmail.com"]
11
+
12
+ spec.summary = %q{Bintray API Client}
13
+ spec.description = %q{Bintray API Client}
14
+ spec.homepage = "https://github.com/jwaterfaucett/bintray-client-ruby"
15
+ spec.license = "MIT"
16
+
17
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(spec|features|examples)/}) }
18
+ spec.bindir = "exe"
19
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
20
+ spec.require_paths = ["lib"]
21
+
22
+ spec.add_dependency 'faraday', '>= 0.9'
23
+ spec.add_dependency 'faraday_middleware', '>= 0.9'
24
+ spec.add_dependency 'faraday-detailed_logger', '>= 0.9'
25
+ spec.add_dependency 'activesupport', '>= 4'
26
+
27
+ spec.add_development_dependency "bundler", "~> 1.12"
28
+ spec.add_development_dependency "rake", "~> 10.0"
29
+ spec.add_development_dependency "rspec", "~> 3.0"
30
+ spec.add_development_dependency 'pry', '~> 0.10'
31
+ end
@@ -0,0 +1,28 @@
1
+ require 'faraday'
2
+ require 'faraday_middleware'
3
+ require 'faraday/detailed_logger'
4
+ require 'active_support/core_ext/object'
5
+ require 'active_support/core_ext/string'
6
+
7
+
8
+ module Bintray
9
+ module Client
10
+ module Ruby
11
+
12
+ autoload :HttpClient, 'bintray/client/ruby/http_client'
13
+ autoload :ConnectionFactory, 'bintray/client/ruby/connection_factory'
14
+ autoload :Api, 'bintray/client/ruby/api'
15
+ autoload :HttpError, 'bintray/client/ruby/http_error'
16
+
17
+ module Resources
18
+ autoload :Base, 'bintray/client/ruby/resources/base'
19
+ autoload :Repositories, 'bintray/client/ruby/resources/repositories'
20
+ end
21
+
22
+ def self.http_client(options = {})
23
+ HttpClient.new(options)
24
+ end
25
+
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,19 @@
1
+ module Bintray
2
+ module Client
3
+ module Ruby
4
+
5
+ class Api
6
+
7
+ def initialize(conn)
8
+ @conn = conn
9
+ end
10
+
11
+ def repositories
12
+ @repositories ||= Resources::Repositories.new(@conn)
13
+ end
14
+
15
+ end
16
+
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,36 @@
1
+ module Bintray
2
+ module Client
3
+ module Ruby
4
+
5
+ class ConnectionFactory
6
+
7
+ attr_reader :options
8
+
9
+ def initialize(options = {})
10
+ @options = options
11
+ end
12
+
13
+ def connect!
14
+ Faraday.new(connection_options) do |conn|
15
+ conn.use(Faraday::Request::BasicAuthentication, options[:username], options[:password])
16
+ conn.use(Faraday::Request::Multipart)
17
+ conn.use(Faraday::Request::UrlEncoded)
18
+ conn.use(Faraday::DetailedLogger::Middleware, options[:logger] || default_logger) if options[:debug] || options[:logger]
19
+ conn.use(FaradayMiddleware::FollowRedirects, limit: 3)
20
+ conn.use(Faraday::Adapter::NetHttp)
21
+ end
22
+ end
23
+
24
+ private
25
+ def connection_options
26
+ { url: options[:url] }
27
+ end
28
+
29
+ def default_logger
30
+ ::Logger.new(STDERR)
31
+ end
32
+ end
33
+
34
+ end
35
+ end
36
+ end
@@ -0,0 +1,53 @@
1
+ module Bintray
2
+ module Client
3
+ module Ruby
4
+
5
+ class HttpClient
6
+
7
+ attr_reader :options, :connection
8
+
9
+ DEFAULT_OPTIONS = {
10
+ base: 'https://api.bintray.com/api',
11
+ version: 'v1',
12
+ username: nil,
13
+ password: nil,
14
+ debug: false,
15
+ logger: nil,
16
+ logger_resource: nil, # use to inspect log contents i.e. Buffer or File
17
+ }
18
+
19
+ def initialize(options = {})
20
+ @options = set_options(options)
21
+ create_connection
22
+ end
23
+
24
+ def api
25
+ @api ||= Api.new(connection)
26
+ end
27
+
28
+ def log
29
+ options[:logger_resource]
30
+ end
31
+
32
+ private
33
+
34
+ def create_connection
35
+ @connection = ConnectionFactory.new(options.merge(url: bintray_url)).connect!
36
+ end
37
+
38
+ def bintray_url
39
+ @bintray_url ||= File.join(options[:base], options[:version])
40
+ end
41
+
42
+ def set_options(options)
43
+ opts = DEFAULT_OPTIONS.merge(options)
44
+ if opts[:username].blank? || opts[:password].blank?
45
+ raise ::ArgumentError.new("username and/or password cannot be empty")
46
+ end
47
+ opts
48
+ end
49
+ end
50
+
51
+ end
52
+ end
53
+ end
@@ -0,0 +1,20 @@
1
+ module Bintray
2
+ module Client
3
+ module Ruby
4
+
5
+ class HttpError < Exception
6
+
7
+ attr_reader :status, :response
8
+
9
+ def initialize(http_response)
10
+ @status = http_response.status
11
+ @response = http_response
12
+
13
+ super('http response error')
14
+ end
15
+
16
+ end
17
+
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,63 @@
1
+ module Bintray
2
+ module Client
3
+ module Ruby
4
+ module Resources
5
+
6
+ class Base
7
+
8
+ def initialize(conn)
9
+ @conn = conn
10
+ end
11
+
12
+ def request(http_method, path, query_params = {}, payload = {}, headers = {})
13
+ @conn.send(http_method) do |req|
14
+ req.url(path)
15
+ set_url_query_params(req, query_params)
16
+ set_headers(req, headers)
17
+ if payload.present?
18
+ req.headers['Content-Type'] = 'application/json'
19
+ req.body = JSON.dump(payload)
20
+ end
21
+ end
22
+ end
23
+
24
+ def parse_response(response)
25
+ return handle_error(response) if response.status >= 300
26
+ handle_ok(response)
27
+ end
28
+
29
+ def create_route(*route)
30
+ File.join(route.flatten.compact.map(&:to_s))
31
+ end
32
+
33
+ private
34
+
35
+ def handle_error(response)
36
+ raise HttpError.new(response)
37
+ end
38
+
39
+ def handle_ok(response)
40
+ JSON.parse(response.body) if response.body.present?
41
+ end
42
+
43
+ def set_url_query_params(request, query_params)
44
+ return unless query_params.present?
45
+ query_params.each do |k,v|
46
+ if v.is_a?(Array)
47
+ request.params[k] = v.join(',')
48
+ else
49
+ request.params[k] = v
50
+ end
51
+ end
52
+ end
53
+
54
+ def set_headers(request, headers)
55
+ headers.each { |k,v| request.headers[k] = v } if headers.present?
56
+ end
57
+
58
+ end
59
+
60
+ end
61
+ end
62
+ end
63
+ end
@@ -0,0 +1,48 @@
1
+ module Bintray
2
+ module Client
3
+ module Ruby
4
+ module Resources
5
+
6
+ class Repositories < Base
7
+
8
+ def url
9
+ @repos ||= '/repos'.freeze
10
+ end
11
+
12
+ # Get Repository
13
+ # GET /repos/:subject
14
+ # GET /repos/:subject/:repo
15
+ def get(subject)
16
+ res = request(:get, create_route(url, subject))
17
+ parse_response(res)
18
+ end
19
+
20
+ # Create Repository
21
+ # POST /repos/:subject/:repo
22
+ # The possible types for a repository are:
23
+ # maven, debian, rpm, docker, npm, opkg, nuget, vagrant and generic (default).
24
+ def create(subject_repo, data = {})
25
+ res = request(:post, create_route(url, subject_repo), {}, data)
26
+ parse_response(res)
27
+ end
28
+
29
+ # Update Repository
30
+ # PATCH /repos/:subject/:repo
31
+ def update(subject_repo, data = {})
32
+ res = request(:patch, create_route(url, subject_repo), {}, data)
33
+ parse_response(res)
34
+ end
35
+
36
+ # Delete Repository
37
+ # DELETE /repos/:subject/:repo
38
+ def delete(subject_repo)
39
+ res = request(:delete, create_route(url, subject_repo))
40
+ parse_response(res)
41
+ end
42
+
43
+ end
44
+
45
+ end
46
+ end
47
+ end
48
+ end
@@ -0,0 +1,20 @@
1
+ module Bintray
2
+ module Client
3
+ module Ruby
4
+
5
+ def self.version
6
+ VERSION.string
7
+ end
8
+
9
+ module VERSION
10
+ MAJOR = 0
11
+ MINOR = 0
12
+ PATCH = 2
13
+
14
+ def self.string
15
+ @@version_string ||= [MAJOR,MINOR,PATCH].join('.').freeze
16
+ end
17
+ end
18
+ end
19
+ end
20
+ end
metadata ADDED
@@ -0,0 +1,174 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: bintray-client-ruby
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.2
5
+ platform: ruby
6
+ authors:
7
+ - John Faucett
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2016-09-08 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ requirement: !ruby/object:Gem::Requirement
15
+ requirements:
16
+ - - ">="
17
+ - !ruby/object:Gem::Version
18
+ version: '0.9'
19
+ name: faraday
20
+ prerelease: false
21
+ type: :runtime
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0.9'
27
+ - !ruby/object:Gem::Dependency
28
+ requirement: !ruby/object:Gem::Requirement
29
+ requirements:
30
+ - - ">="
31
+ - !ruby/object:Gem::Version
32
+ version: '0.9'
33
+ name: faraday_middleware
34
+ prerelease: false
35
+ type: :runtime
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0.9'
41
+ - !ruby/object:Gem::Dependency
42
+ requirement: !ruby/object:Gem::Requirement
43
+ requirements:
44
+ - - ">="
45
+ - !ruby/object:Gem::Version
46
+ version: '0.9'
47
+ name: faraday-detailed_logger
48
+ prerelease: false
49
+ type: :runtime
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0.9'
55
+ - !ruby/object:Gem::Dependency
56
+ requirement: !ruby/object:Gem::Requirement
57
+ requirements:
58
+ - - ">="
59
+ - !ruby/object:Gem::Version
60
+ version: '4'
61
+ name: activesupport
62
+ prerelease: false
63
+ type: :runtime
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '4'
69
+ - !ruby/object:Gem::Dependency
70
+ requirement: !ruby/object:Gem::Requirement
71
+ requirements:
72
+ - - "~>"
73
+ - !ruby/object:Gem::Version
74
+ version: '1.12'
75
+ name: bundler
76
+ prerelease: false
77
+ type: :development
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '1.12'
83
+ - !ruby/object:Gem::Dependency
84
+ requirement: !ruby/object:Gem::Requirement
85
+ requirements:
86
+ - - "~>"
87
+ - !ruby/object:Gem::Version
88
+ version: '10.0'
89
+ name: rake
90
+ prerelease: false
91
+ type: :development
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: '10.0'
97
+ - !ruby/object:Gem::Dependency
98
+ requirement: !ruby/object:Gem::Requirement
99
+ requirements:
100
+ - - "~>"
101
+ - !ruby/object:Gem::Version
102
+ version: '3.0'
103
+ name: rspec
104
+ prerelease: false
105
+ type: :development
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - "~>"
109
+ - !ruby/object:Gem::Version
110
+ version: '3.0'
111
+ - !ruby/object:Gem::Dependency
112
+ requirement: !ruby/object:Gem::Requirement
113
+ requirements:
114
+ - - "~>"
115
+ - !ruby/object:Gem::Version
116
+ version: '0.10'
117
+ name: pry
118
+ prerelease: false
119
+ type: :development
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - "~>"
123
+ - !ruby/object:Gem::Version
124
+ version: '0.10'
125
+ description: Bintray API Client
126
+ email:
127
+ - jwaterfaucett@gmail.com
128
+ executables: []
129
+ extensions: []
130
+ extra_rdoc_files: []
131
+ files:
132
+ - ".gitignore"
133
+ - ".rspec"
134
+ - ".travis.yml"
135
+ - Gemfile
136
+ - LICENSE.txt
137
+ - README.md
138
+ - Rakefile
139
+ - bin/console
140
+ - bin/setup
141
+ - bintray-client-ruby.gemspec
142
+ - lib/bintray/client/ruby.rb
143
+ - lib/bintray/client/ruby/api.rb
144
+ - lib/bintray/client/ruby/connection_factory.rb
145
+ - lib/bintray/client/ruby/http_client.rb
146
+ - lib/bintray/client/ruby/http_error.rb
147
+ - lib/bintray/client/ruby/resources/base.rb
148
+ - lib/bintray/client/ruby/resources/repositories.rb
149
+ - lib/bintray/client/ruby/version.rb
150
+ homepage: https://github.com/jwaterfaucett/bintray-client-ruby
151
+ licenses:
152
+ - MIT
153
+ metadata: {}
154
+ post_install_message:
155
+ rdoc_options: []
156
+ require_paths:
157
+ - lib
158
+ required_ruby_version: !ruby/object:Gem::Requirement
159
+ requirements:
160
+ - - ">="
161
+ - !ruby/object:Gem::Version
162
+ version: '0'
163
+ required_rubygems_version: !ruby/object:Gem::Requirement
164
+ requirements:
165
+ - - ">="
166
+ - !ruby/object:Gem::Version
167
+ version: '0'
168
+ requirements: []
169
+ rubyforge_project:
170
+ rubygems_version: 2.6.4
171
+ signing_key:
172
+ specification_version: 4
173
+ summary: Bintray API Client
174
+ test_files: []