rubygems_api 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 27da6ad6aae93b4412daae9e006b1e51b6baa45c
4
+ data.tar.gz: 043e7279ebfb21b1843e365d5dd462fa7e6739ab
5
+ SHA512:
6
+ metadata.gz: 49409118881ff6116982b27de9e5b565400d9b164a9e4f0bc18fa631fee5d2f5b141139aa1514b29a621054cd5e6f29b21b64959f01d960e63b1244ff7834ba6
7
+ data.tar.gz: 999d9d3680cc11d071ee944bef1fccc8e4512345dbda624bf7c2f792e1eaee7f70e4ff1e1125035889474567e3a161f7f0ed02378bae2f85cf7c6c895b68520d
data/.gitignore ADDED
@@ -0,0 +1,10 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ test/.DS_Store
data/.travis.yml ADDED
@@ -0,0 +1,17 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.0.0
4
+ - 2.1.0
5
+ - 2.1.5
6
+ - 2.2.0
7
+ - 2.2.1
8
+
9
+ before_install:
10
+ - gem update --system
11
+ - gem --version
12
+
13
+ gemfile:
14
+ - Gemfile
15
+
16
+ notifications:
17
+ email: false
data/Gemfile ADDED
@@ -0,0 +1,9 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in rubygems_api.gemspec
4
+ gemspec
5
+ gem 'rake', group: :test, require: nil
6
+ gem 'minitest', group: :test, require: nil
7
+ gem 'bundler', group: :test, require: nil
8
+ gem 'codeclimate-test-reporter', group: :test, require: nil
9
+ gem 'hurley'
data/README.md ADDED
@@ -0,0 +1,41 @@
1
+ [![Build Status](https://travis-ci.org/kkirsche/rubygems_api.svg?branch=master)](https://travis-ci.org/kkirsche/rubygems_api) [![Code Climate](https://codeclimate.com/github/kkirsche/rubygems_api/badges/gpa.svg)](https://codeclimate.com/github/kkirsche/rubygems_api) [![Test Coverage](https://codeclimate.com/github/kkirsche/rubygems_api/badges/coverage.svg)](https://codeclimate.com/github/kkirsche/rubygems_api)
2
+
3
+ # RubyGems API Client
4
+
5
+ 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/rubygems_api`. To experiment with that code, run `bin/console` for an interactive prompt.
6
+
7
+ TODO: Delete this and the text above, and describe your gem
8
+
9
+ ## Installation
10
+
11
+ Add this line to your application's Gemfile:
12
+
13
+ ```ruby
14
+ gem 'rubygems_api'
15
+ ```
16
+
17
+ And then execute:
18
+
19
+ $ bundle
20
+
21
+ Or install it yourself as:
22
+
23
+ $ gem install rubygems_api
24
+
25
+ ## Usage
26
+
27
+ TODO: Write usage instructions here
28
+
29
+ ## Development
30
+
31
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `bin/console` for an interactive prompt that will allow you to experiment.
32
+
33
+ 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` to create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
34
+
35
+ ## Contributing
36
+
37
+ 1. Fork it ( https://github.com/[my-github-username]/rubygems_api/fork )
38
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
39
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
40
+ 4. Push to the branch (`git push origin my-new-feature`)
41
+ 5. Create a new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,11 @@
1
+ require "bundler/gem_tasks"
2
+ require "rake/testtask"
3
+
4
+ Rake::TestTask.new(:test) do |t|
5
+ t.libs << "test/"
6
+ t.libs << "bin/"
7
+ t.libs << "lib/"
8
+ t.pattern = "test/rubygems_api/**/*_spec.rb"
9
+ end
10
+
11
+ task :default => :test
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "rubygems_api"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start
data/bin/setup ADDED
@@ -0,0 +1,7 @@
1
+ #!/bin/bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+
5
+ bundle install
6
+
7
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,7 @@
1
+ require "rubygems_api/version"
2
+ require "rubygems_api/client"
3
+
4
+ module Rubygems
5
+ module API
6
+ end
7
+ end
@@ -0,0 +1,18 @@
1
+ module Rubygems
2
+ module API
3
+ # Method relating to RubyGems Activity
4
+ module Activities
5
+ def rubygems_total_downloads(format = 'json', args = {})
6
+ get("downloads.#{format}", format, nil, args)
7
+ end
8
+
9
+ def latest_activity(format = 'json', args = {})
10
+ get("activity/latest.#{format}", format, nil, args)
11
+ end
12
+
13
+ def just_updated(format = 'json', args = {})
14
+ get("activity/just_updated.#{format}", format, nil, args)
15
+ end
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,22 @@
1
+ module Rubygems
2
+ module API
3
+ # Method relating to gem ownership
4
+ module GemOwners
5
+ def gems_by_owner(username, format = 'json', args = {})
6
+ get("owners/#{username}/gems.#{format}", format, nil, args)
7
+ end
8
+
9
+ def gem_owners(gem_name, format = 'json', args = {})
10
+ get("gems/#{gem_name}/owners.#{format}", format, nil, args)
11
+ end
12
+
13
+ def add_gem_owner(gem_name, email, args = {})
14
+ @client.post("gems/#{gem_name}/owners", email: email)
15
+ end
16
+
17
+ def remove_gem_owner(gem_name, email, args = {})
18
+ @client.delete("gems/#{gem_name}/owners", email: email)
19
+ end
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,67 @@
1
+ module Rubygems
2
+ module API
3
+ # Method relating to gem ownership
4
+ module Gems
5
+ def gems_by_owner(username, format = 'json', args = {})
6
+ get("owners/#{username}/gems.#{format}", format, nil, args)
7
+ end
8
+
9
+ def gem_owners(gem_name, format = 'json', args = {})
10
+ get("gems/#{gem_name}/owners.#{format}", format, nil, args)
11
+ end
12
+
13
+ def add_gem_owner(gem_name, email, args = {})
14
+ @client.post("gems/#{gem_name}/owners", email: email)
15
+ end
16
+
17
+ def remove_gem_owner(gem_name, email, args = {})
18
+ @client.delete("gems/#{gem_name}/owners", email: email)
19
+ end
20
+
21
+ def gem_info(name, format = 'json', args = {})
22
+ get("gems/#{name}.#{format}", format, nil, args)
23
+ end
24
+
25
+ def gem_search(query, format = 'json', args = { page: 1 })
26
+ get("search.#{format}", format, { query: query, page: args[:page] }, args)
27
+ end
28
+
29
+ def my_gems(format = 'json', args = {})
30
+ get("gems.#{format}", format, nil, args)
31
+ end
32
+
33
+ def submit_gem(gem_file)
34
+ @client.post(
35
+ 'gems',
36
+ file: Hurley::UploadIO.new(gem_file.read, 'application/octet-stream'))
37
+ end
38
+
39
+ def yank_gem(gem_name, gem_version = nil, args = {})
40
+ yank_api('gems/yank', :delete, gem_name, gem_version, args)
41
+ end
42
+
43
+ def unyank_gem(gem_name, gem_version = nil, args = {})
44
+ yank_api('gems/unyank', :put, gem_name, gem_version, args)
45
+ end
46
+
47
+ def gem_versions(gem_name, format = 'json', args = {})
48
+ get("versions/#{gem_name}.#{format}", format, nil, args)
49
+ end
50
+
51
+ def gem_downloads(gem_name, gem_version, format = 'json', args = {})
52
+ get("downloads/#{gem_name}-#{gem_version}.#{format}", format, nil, args)
53
+ end
54
+
55
+ def gem_dependencies(args = [])
56
+ response = @client.get('dependencies', {}.tap do |hash|
57
+ args = Array.new(1, args) if args.is_a? String
58
+ hash[:gems] = args.join(',')
59
+ end)
60
+
61
+ response.body = Marshal.load(response.body)
62
+
63
+ response
64
+ end
65
+ end
66
+ end
67
+ end
@@ -0,0 +1,23 @@
1
+ module Rubygems
2
+ module API
3
+ # Method relating to RubyGems Webhooks
4
+ module Webhooks
5
+ def view_webhooks(format = 'json', args = {})
6
+ get("web_hooks.#{format}", format, nil, args)
7
+ end
8
+
9
+ def register_webhook(gem_name, url)
10
+ @client.post('web_hooks', gem_name: gem_name,
11
+ url: url)
12
+ end
13
+
14
+ def remove_webhook(gem_name, url)
15
+ @client.delete('web_hooks/remove', gem_name: gem_name, url: url)
16
+ end
17
+
18
+ def fire_webhook(gem_name, url)
19
+ @client.post('web_hooks/fire', gem_name: gem_name, url: url)
20
+ end
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,63 @@
1
+ require 'rubygems_api/utilities'
2
+ require 'rubygems_api/actions/activities'
3
+ require 'rubygems_api/actions/gem_owners'
4
+ require 'rubygems_api/actions/gems'
5
+ require 'rubygems_api/actions/webhooks'
6
+ require 'hurley'
7
+ require 'json'
8
+ require 'yaml'
9
+ require 'cgi'
10
+
11
+ module Rubygems
12
+ module API
13
+ class Client
14
+ include Rubygems::API::Utilities
15
+ include Rubygems::API::Activities
16
+ include Rubygems::API::GemOwners
17
+ include Rubygems::API::Gems
18
+ include Rubygems::API::Webhooks
19
+ attr_accessor :client, :api_key
20
+
21
+ def initialize(arguments = {})
22
+ @api_key ||= arguments[:api_key] || \
23
+ nil
24
+
25
+ @host = 'https://rubygems.org/'
26
+ @api_endpoint = '/api/v1'
27
+
28
+ @client = Hurley::Client.new 'https://rubygems.org/api/v1/'
29
+ ssl(arguments)
30
+ @client.request_options.redirection_limit = 10
31
+
32
+ @client.header[:Authorization] = @api_key unless @api_key.nil?
33
+
34
+ @client
35
+ end
36
+
37
+ def api_key(key = nil)
38
+ @api_key = key unless key.nil?
39
+ @client.header[:Authorization] = @api_key unless @api_key.nil?
40
+
41
+ @api_key
42
+ end
43
+
44
+ def set_api_key(username, password, format = 'json', args = {})
45
+ creds = CGI.escape(username) + ':' + CGI.escape(password)
46
+ if validate_format(format)
47
+ response = @client.get("https://#{creds}@rubygems.org/api/v1/api_key.#{format}") do |req|
48
+ req.header[:Authorization] = req.url.basic_auth.gsub!(/(\n|\r|\t)+/, '')
49
+ end
50
+
51
+ if response.success?
52
+ format_body response: response, skip_format: args[:skip_format],
53
+ format: format
54
+
55
+ api_key(response.body['rubygems_api_key'])
56
+ end
57
+ end
58
+
59
+ response
60
+ end
61
+ end
62
+ end
63
+ end
@@ -0,0 +1,70 @@
1
+ module Rubygems
2
+ module API
3
+ # The Utilities module allows us to use the same functions throughout
4
+ module Utilities
5
+ def validate_format(format)
6
+ return true if format == 'json' || format == 'yaml'
7
+
8
+ fail RuntimeError,
9
+ 'Invalid format requested. Please select either json or yaml.'
10
+ end
11
+
12
+ def format_body(args = {})
13
+ if args[:skip_format].nil?
14
+ response = format_json_body(args[:response]) if args[:format] == 'json'
15
+ response = format_yaml_body(args[:response]) if args[:format] == 'yaml'
16
+ end
17
+
18
+ response
19
+ end
20
+
21
+ def format_json_body(response)
22
+ response.body = JSON.parse(response.body)
23
+
24
+ response
25
+ end
26
+
27
+ def format_yaml_body(response)
28
+ response.body = YAML.load(response.body)
29
+
30
+ response
31
+ end
32
+
33
+ def ssl(arguments)
34
+ @skip_verification = arguments[:skip_verification] || \
35
+ true
36
+
37
+ @ca_path = arguments[:ca_path] || \
38
+ `openssl version -d`.split(/"/)[1] + '/certs'
39
+
40
+ @ssl_version = arguments[:ssl_version] || \
41
+ 'SSLv23'
42
+
43
+ @client.ssl_options.skip_verification = @skip_verification
44
+ @client.ssl_options.ca_path = @ca_path
45
+ @client.ssl_options.version = @ssl_version
46
+ end
47
+
48
+ def get(url, format, hash, args = {})
49
+ if validate_format format
50
+ response = @client.get(url, hash)
51
+
52
+ format_body response: response, skip_format: args[:skip_format],
53
+ format: format if response.success?
54
+ end
55
+
56
+ response
57
+ end
58
+
59
+ def yank_api(url, method_symbol, gem_name, gem_version, args = {})
60
+ response = @client.method(method_symbol).call(url, {}.tap do |hash|
61
+ hash[:gem_name] = gem_name
62
+ hash[:gem_version] = gem_version unless gem_version.nil?
63
+ hash[:platform] = args[:platform] unless args[:platform].nil?
64
+ end)
65
+
66
+ response
67
+ end
68
+ end
69
+ end
70
+ end
@@ -0,0 +1,5 @@
1
+ module Rubygems
2
+ module API
3
+ VERSION = '1.0.0'
4
+ end
5
+ end
@@ -0,0 +1,27 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'rubygems_api/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "rubygems_api"
8
+ spec.version = Rubygems::API::VERSION
9
+ spec.authors = ["Kevin Kirsche"]
10
+ spec.email = ["kevin.kirsche@verizon.com"]
11
+
12
+ spec.summary = %q{RubyGems v1 API client.}
13
+ spec.description = %q{Full featured RubyGems v1 API client using Hurley.}
14
+ spec.homepage = "https://github.com/kkirsche/rubygems_api"
15
+ spec.license = "MIT"
16
+
17
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
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_development_dependency 'bundler', '~> 1.9'
23
+ spec.add_development_dependency 'rake', '~> 10.4'
24
+ spec.add_development_dependency 'minitest', '~> 5.5'
25
+ spec.add_development_dependency 'codeclimate-test-reporter', '~> 0.4'
26
+ spec.add_runtime_dependency 'hurley', '~> 0'
27
+ end
metadata ADDED
@@ -0,0 +1,130 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: rubygems_api
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Kevin Kirsche
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2015-04-03 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.9'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.9'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.4'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.4'
41
+ - !ruby/object:Gem::Dependency
42
+ name: minitest
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '5.5'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '5.5'
55
+ - !ruby/object:Gem::Dependency
56
+ name: codeclimate-test-reporter
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '0.4'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '0.4'
69
+ - !ruby/object:Gem::Dependency
70
+ name: hurley
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :runtime
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ description: Full featured RubyGems v1 API client using Hurley.
84
+ email:
85
+ - kevin.kirsche@verizon.com
86
+ executables: []
87
+ extensions: []
88
+ extra_rdoc_files: []
89
+ files:
90
+ - ".gitignore"
91
+ - ".travis.yml"
92
+ - Gemfile
93
+ - README.md
94
+ - Rakefile
95
+ - bin/console
96
+ - bin/setup
97
+ - lib/rubygems_api.rb
98
+ - lib/rubygems_api/actions/activities.rb
99
+ - lib/rubygems_api/actions/gem_owners.rb
100
+ - lib/rubygems_api/actions/gems.rb
101
+ - lib/rubygems_api/actions/webhooks.rb
102
+ - lib/rubygems_api/client.rb
103
+ - lib/rubygems_api/utilities.rb
104
+ - lib/rubygems_api/version.rb
105
+ - rubygems_api.gemspec
106
+ homepage: https://github.com/kkirsche/rubygems_api
107
+ licenses:
108
+ - MIT
109
+ metadata: {}
110
+ post_install_message:
111
+ rdoc_options: []
112
+ require_paths:
113
+ - lib
114
+ required_ruby_version: !ruby/object:Gem::Requirement
115
+ requirements:
116
+ - - ">="
117
+ - !ruby/object:Gem::Version
118
+ version: '0'
119
+ required_rubygems_version: !ruby/object:Gem::Requirement
120
+ requirements:
121
+ - - ">="
122
+ - !ruby/object:Gem::Version
123
+ version: '0'
124
+ requirements: []
125
+ rubyforge_project:
126
+ rubygems_version: 2.4.3
127
+ signing_key:
128
+ specification_version: 4
129
+ summary: RubyGems v1 API client.
130
+ test_files: []