drone-ruby 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: b7b1defd7670b508347625a4691807a67c0c2ecf
4
+ data.tar.gz: efa4e4e2f1dccad2cee8e8620e559483ab33ab6d
5
+ SHA512:
6
+ metadata.gz: 4f9766176de3c4b4857f500a9feb4df126d756774da79ac424a1d18815426f187ac97f52b108977223ee00f4cdbedd6c55c8044541fc07426b53cbb39b87d910
7
+ data.tar.gz: ef7b6c39b89b208f552037aa23ceace0ffee49a714bb6042591b042f6158b3ca31d5776a2633236cf171c6cbcb6674eda3739f2e03951a1a07cd202d4435b7e2
@@ -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/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in drone-ruby.gemspec
4
+ gemspec
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2015 june29
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.
@@ -0,0 +1,37 @@
1
+ # drone-ruby
2
+
3
+ [![Build Status](https://drone.io/github.com/june29/drone-ruby/status.png)](https://drone.io/github.com/june29/drone-ruby/latest) [![Dependency Status](https://gemnasium.com/june29/drone-ruby.svg)](https://gemnasium.com/june29/drone-ruby) [![Code Climate](https://codeclimate.com/github/june29/drone-ruby/badges/gpa.svg)](https://codeclimate.com/github/june29/drone-ruby)
4
+
5
+ A Ruby interface to the Drone.io API.
6
+
7
+ http://readme.drone.io/api/overview/
8
+
9
+ ## Installation
10
+
11
+ Add this line to your application's Gemfile:
12
+
13
+ ```ruby
14
+ gem 'drone-ruby'
15
+ ```
16
+
17
+ And then execute:
18
+
19
+ $ bundle
20
+
21
+ Or install it yourself as:
22
+
23
+ $ gem install drone-ruby
24
+
25
+ ## Development
26
+
27
+ After checking out the repo, run `bin/setup` to install dependencies. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
28
+
29
+ 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).
30
+
31
+ ## Contributing
32
+
33
+ Bug reports and pull requests are welcome on GitHub at https://github.com/june29/drone-ruby. 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.
34
+
35
+ ## License
36
+
37
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
@@ -0,0 +1,7 @@
1
+ require "bundler/gem_tasks"
2
+ require "rake/testtask"
3
+
4
+ Rake::TestTask.new do |t|
5
+ t.libs.push "lib"
6
+ t.test_files = FileList["test/**/*_test.rb"]
7
+ end
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "drone"
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
@@ -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,28 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'drone/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "drone-ruby"
8
+ spec.version = Drone::VERSION
9
+ spec.authors = ["june29"]
10
+ spec.email = ["june29.jp@gmail.com"]
11
+
12
+ spec.summary = "API client for Drone.io"
13
+ spec.homepage = "https://github.com/june29/drone-ruby"
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
17
+ spec.bindir = "exe"
18
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_dependency "httpclient"
22
+
23
+ spec.add_development_dependency "bundler", "~> 1.10"
24
+ spec.add_development_dependency "rake", "~> 10.0"
25
+ spec.add_development_dependency "minitest"
26
+ spec.add_development_dependency "minitest-reporters"
27
+ spec.add_development_dependency "webmock"
28
+ end
@@ -0,0 +1,5 @@
1
+ require "drone/version"
2
+ require "drone/client"
3
+ require "drone/user"
4
+ require "drone/repository"
5
+ require "drone/commit"
@@ -0,0 +1,70 @@
1
+ require "httpclient"
2
+ require "json"
3
+ require "time"
4
+
5
+ module Drone
6
+ class Client
7
+ DEFAULT_HOST = "drone.io"
8
+ USER_AGENT = "#{self}/#{VERSION}"
9
+
10
+ attr_accessor :http
11
+
12
+ def initialize(host: nil, access_token: nil)
13
+ @host = host || DEFAULT_HOST
14
+ @access_token = access_token
15
+
16
+ @http = HTTPClient.new
17
+ @http.agent_name = USER_AGENT
18
+ end
19
+
20
+ def user
21
+ url = "https://#{@host}/api/user"
22
+
23
+ response = get_json(url)
24
+ User.build_with_hash(response)
25
+ end
26
+
27
+ def repository(path)
28
+ url = "#{base_url}/repos/#{path}"
29
+
30
+ response = get_json(url)
31
+ Repository.build_with_hash(response)
32
+ end
33
+
34
+ def commits(repos: nil)
35
+ url = "#{base_url}/repos/#{repos.path}/commits"
36
+
37
+ response = get_json(url)
38
+ response.map { |commit| Commit.build_with_hash(commit) }
39
+ end
40
+
41
+ def rebuild(repos: nil, branch: nil, commit: nil)
42
+ url = "#{base_url}/repos/#{repos.path}/branches/#{branch}/commits/#{commit.sha}"
43
+
44
+ post(url)
45
+ end
46
+
47
+ def console(repos: nil, branch: nil, commit: nil)
48
+ url = "#{base_url}/repos/#{repos.path}/branches/#{branch}/commits/#{commit.sha}/console"
49
+ get(url)
50
+ end
51
+
52
+ private
53
+
54
+ def base_url
55
+ "https://#{@host}/api"
56
+ end
57
+
58
+ def get(url)
59
+ @http.get(url, access_token: @access_token).body
60
+ end
61
+
62
+ def get_json(url)
63
+ JSON.parse(@http.get(url, access_token: @access_token).body)
64
+ end
65
+
66
+ def post(url)
67
+ @http.post(url, access_token: @access_token)
68
+ end
69
+ end
70
+ end
@@ -0,0 +1,46 @@
1
+ module Drone
2
+ class Commit
3
+ attr_reader :id, :status, :sha, :started_at, :finished_at, :duration, :branch, :pull_request, :message, :author, :gravatar, :timestamp, :created_at, :updated_at
4
+
5
+ def initialize(
6
+ id: nil, status: nil, sha: nil,
7
+ started_at: nil, finished_at: nil, duration: nil,
8
+ branch: nil, pull_request: nil, message: nil,
9
+ author: nil, gravatar: nil,
10
+ timestamp: nil, created_at: nil, updated_at: nil)
11
+ @id = id
12
+ @status = status
13
+ @sha = sha
14
+ @started_at = started_at
15
+ @finished_at = finished_at
16
+ @duration = duration
17
+ @branch = branch
18
+ @pull_request = pull_request
19
+ @message = message
20
+ @author = author
21
+ @gravatar = gravatar
22
+ @timestamp = timestamp
23
+ @created_at = created_at
24
+ @updated_at = updated_at
25
+ end
26
+
27
+ def self.build_with_hash(hash)
28
+ Commit.new(
29
+ id: hash["id"],
30
+ status: hash["status"],
31
+ sha: hash["sha"],
32
+ started_at: hash["started_at"],
33
+ finished_at: hash["finished_at"],
34
+ duration: hash["duration"],
35
+ branch: hash["branch"],
36
+ pull_request: hash["pull_request"],
37
+ message: hash["message"],
38
+ author: hash["author"],
39
+ gravatar: hash["gravatar"],
40
+ timestamp: Time.parse(hash["timestamp"]),
41
+ created_at: hash["created_at"],
42
+ updated_at: hash["updated_at"]
43
+ )
44
+ end
45
+ end
46
+ end
@@ -0,0 +1,53 @@
1
+ module Drone
2
+ class Repository
3
+ attr_reader :remote, :host, :owner, :name, :url, :clone_url, :git_url, :ssh_url, :active, :private, :privileged, :post_commits, :pull_requests, :timeout, :created_at, :updated_at
4
+
5
+ def initialize(
6
+ remote: nil, host: nil, owner: nil, name: nil,
7
+ url: nil, clone_url: nil, git_url: nil, ssh_url: nil,
8
+ active: nil, private: nil, privileged: nil, post_commits: nil, pull_requests: nil,
9
+ timeout: nil, created_at: nil, updated_at: nil)
10
+ @remote = remote
11
+ @host = host
12
+ @owner = owner
13
+ @name = name
14
+ @url = url
15
+ @clone_url = clone_url
16
+ @git_url = git_url
17
+ @ssh_url = ssh_url
18
+ @active = active
19
+ @private = private
20
+ @privileged = privileged
21
+ @post_commits = post_commits
22
+ @pull_requests = pull_requests
23
+ @timeout = timeout
24
+ @created_at = created_at
25
+ @updated_at = updated_at
26
+ end
27
+
28
+ def path
29
+ [@host, @owner, @name].join("/")
30
+ end
31
+
32
+ def self.build_with_hash(hash)
33
+ Repository.new(
34
+ remote: hash["remote"],
35
+ host: hash["host"],
36
+ owner: hash["owner"],
37
+ name: hash["name"],
38
+ url: hash["url"],
39
+ clone_url: hash["clone_url"],
40
+ git_url: hash["git_url"],
41
+ ssh_url: hash["ssh_url"],
42
+ active: hash["active"],
43
+ private: hash["private"],
44
+ privileged: hash["privileged"],
45
+ post_commits: hash["post_commits"],
46
+ pull_requests: hash["pull_requests"],
47
+ timeout: hash["timeout"],
48
+ created_at: hash["created_at"],
49
+ updated_at: hash["updated_at"]
50
+ )
51
+ end
52
+ end
53
+ end
@@ -0,0 +1,34 @@
1
+ module Drone
2
+ class User
3
+ attr_reader :remote, :login, :name, :email, :gravatar, :admin, :active, :created_at, :updated_at, :synced_at
4
+
5
+ def initialize(
6
+ remote: nil, login: nil, name: nil, email: nil, gravatar: nil, admin: nil, active: nil, created_at: nil, updated_at: nil, synced_at: nil)
7
+ @remote = remote
8
+ @login = login
9
+ @name = name
10
+ @email = email
11
+ @gravatar = gravatar
12
+ @admin = admin
13
+ @active = active
14
+ @created_at = created_at
15
+ @updated_at = updated_at
16
+ @synced_at = synced_at
17
+ end
18
+
19
+ def self.build_with_hash(hash)
20
+ User.new(
21
+ remote: hash["remote"],
22
+ login: hash["login"],
23
+ name: hash["name"],
24
+ email: hash["email"],
25
+ gravatar: hash["gravatar"],
26
+ admin: hash["admin"],
27
+ active: hash["active"],
28
+ created_at: hash["created_at"],
29
+ updated_at: hash["updated_at"],
30
+ synced_at: hash["synced_at"]
31
+ )
32
+ end
33
+ end
34
+ end
@@ -0,0 +1,3 @@
1
+ module Drone
2
+ VERSION = "0.1.0"
3
+ end
metadata ADDED
@@ -0,0 +1,142 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: drone-ruby
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - june29
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2015-07-21 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: httpclient
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
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
+ - !ruby/object:Gem::Dependency
70
+ name: minitest-reporters
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: webmock
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ description:
98
+ email:
99
+ - june29.jp@gmail.com
100
+ executables: []
101
+ extensions: []
102
+ extra_rdoc_files: []
103
+ files:
104
+ - ".gitignore"
105
+ - Gemfile
106
+ - LICENSE.txt
107
+ - README.md
108
+ - Rakefile
109
+ - bin/console
110
+ - bin/setup
111
+ - drone-ruby.gemspec
112
+ - lib/drone.rb
113
+ - lib/drone/client.rb
114
+ - lib/drone/commit.rb
115
+ - lib/drone/repository.rb
116
+ - lib/drone/user.rb
117
+ - lib/drone/version.rb
118
+ homepage: https://github.com/june29/drone-ruby
119
+ licenses:
120
+ - MIT
121
+ metadata: {}
122
+ post_install_message:
123
+ rdoc_options: []
124
+ require_paths:
125
+ - lib
126
+ required_ruby_version: !ruby/object:Gem::Requirement
127
+ requirements:
128
+ - - ">="
129
+ - !ruby/object:Gem::Version
130
+ version: '0'
131
+ required_rubygems_version: !ruby/object:Gem::Requirement
132
+ requirements:
133
+ - - ">="
134
+ - !ruby/object:Gem::Version
135
+ version: '0'
136
+ requirements: []
137
+ rubyforge_project:
138
+ rubygems_version: 2.4.5
139
+ signing_key:
140
+ specification_version: 4
141
+ summary: API client for Drone.io
142
+ test_files: []