circleci 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
data/README.md ADDED
@@ -0,0 +1,50 @@
1
+ circleci
2
+ ========
3
+
4
+ [![Build Status](https://travis-ci.org/mtchavez/circleci.png)](https://travis-ci.org/mtchavez/circleci)
5
+
6
+ Circle CI API Wrapper
7
+
8
+ ## Install
9
+
10
+ ```ruby
11
+ gem install 'circleci'
12
+ ```
13
+
14
+ or with Bundler
15
+
16
+ ```ruby
17
+ gem 'circleci'
18
+ ```
19
+
20
+ ## Usage
21
+
22
+ ### Configuring
23
+
24
+ Configure using an API token from Circle
25
+
26
+ ```ruby
27
+ CircleCi.configure do |config|
28
+ config.token = 'my-token'
29
+ end
30
+ ```
31
+
32
+ ### User
33
+
34
+ The ```/me``` endpoint provides information about the signed in user.
35
+
36
+ ```ruby
37
+ res = CircleCi::User.me
38
+ res.succes? # True
39
+ res.body
40
+ ```
41
+
42
+ Example response
43
+
44
+ ```json
45
+ {
46
+ "basic_email_prefs" : "smart", // can be "smart", "none" or "all"
47
+ "login" : "pbiggar" // your github username
48
+ }
49
+ ```
50
+
data/lib/circleci.rb ADDED
@@ -0,0 +1,44 @@
1
+ require 'json'
2
+ require 'rest-client'
3
+ require 'net/http'
4
+ require 'hashie'
5
+
6
+ files = [
7
+ 'build',
8
+ 'config',
9
+ 'http',
10
+ 'project',
11
+ 'request_error',
12
+ 'response',
13
+ 'user'
14
+ ]
15
+
16
+ files.each { |path| require_relative "./circleci/#{path}" }
17
+
18
+
19
+ module CircleCi
20
+
21
+ extend self
22
+
23
+ #
24
+ # @example Configure CircleCi with your token
25
+ # CircleCi.configure do |config|
26
+ # config.token = 'my-token'
27
+ # end
28
+
29
+ def configure
30
+ yield config
31
+ end
32
+
33
+ #
34
+ # @return [CircleCi::Config]
35
+
36
+ def config
37
+ @config ||= Config.new
38
+ end
39
+
40
+ def http # @private
41
+ Http.new(config)
42
+ end
43
+
44
+ end
@@ -0,0 +1,15 @@
1
+ module CircleCi
2
+
3
+ class Build
4
+
5
+ def self.get username, project, build
6
+ CircleCi.http.get "/project/#{username}/#{project}/#{build}"
7
+ end
8
+
9
+ def self.retry username, project, build
10
+ CircleCi.http.post "/project/#{username}/#{project}/#{build}/retry"
11
+ end
12
+
13
+ end
14
+
15
+ end
@@ -0,0 +1,27 @@
1
+ module CircleCi
2
+ ##
3
+ #
4
+ # Config class used internally.
5
+ # Configure API calls using AlPapi.configure
6
+
7
+ class Config
8
+
9
+ VERSION = 'v1'
10
+ DEFAULT_HOST = "https://circleci.com/api/#{VERSION}"
11
+ DEFAULT_PORT = 80 # @private
12
+
13
+ attr_accessor :token
14
+ attr_reader :host, :port # @private
15
+
16
+ ##
17
+ #
18
+ # @private
19
+
20
+ def initialize
21
+ @host = DEFAULT_HOST
22
+ @port = DEFAULT_PORT
23
+ end
24
+
25
+ end
26
+
27
+ end
@@ -0,0 +1,55 @@
1
+ module CircleCi
2
+
3
+ class Http # @private
4
+
5
+ attr_accessor :errors, :response, :success, :config, :over_limit, :suspended
6
+
7
+ def initialize(_config)
8
+ @config, @errors, @success, @over_limit, @suspended = _config, [], false, false, false
9
+ end
10
+
11
+ def get(path, params = {})
12
+ request 'get', "#{path}?#{RestClient::Payload.generate(build_params(params))}"
13
+ end
14
+
15
+ def post(path, params = {})
16
+ request 'post', "#{path}?#{RestClient::Payload.generate(build_params(params))}"
17
+ end
18
+
19
+ def delete(path, params = {})
20
+ request 'delete', "#{path}?#{RestClient::Payload.generate(build_params(params))}"
21
+ end
22
+
23
+ def headers
24
+ { 'accept' => 'application/json', 'content-type' => 'application/json' }
25
+ end
26
+
27
+ def build_params(params = {})
28
+ params.merge('circle-token' => @config.token)
29
+ end
30
+
31
+ def request(http_verb, path)
32
+ url = "#{@config.host}#{path}"
33
+ args = [http_verb, url, headers]
34
+
35
+ response = RestClient.send *args do |res, req, raw_res|
36
+ body = res.body
37
+ code = raw_res.code.to_i
38
+
39
+ self.response = body
40
+ self.errors = []
41
+
42
+ if code == 200
43
+ self.response = JSON.parse(body) rescue body
44
+ self.success = true
45
+ else
46
+ self.errors << RequestError.new(body, code, path)
47
+ end
48
+
49
+ Response.new(self, code, path)
50
+ end
51
+ end
52
+
53
+ end
54
+
55
+ end
@@ -0,0 +1,20 @@
1
+ module CircleCi
2
+
3
+ class Project
4
+
5
+ def self.all
6
+ CircleCi.http.get '/projects'
7
+ end
8
+
9
+ def self.recent_builds username, project
10
+ CircleCi.http.get "/project/#{username}/#{project}"
11
+ end
12
+
13
+ def self.clear_cache username, project
14
+ CircleCi.http.delete "/project/#{username}/#{project}/build-cache"
15
+ end
16
+
17
+ end
18
+
19
+ end
20
+
@@ -0,0 +1,13 @@
1
+ module CircleCi
2
+
3
+ class RequestError
4
+
5
+ attr_reader :message, :code, :path
6
+
7
+ def initialize(_message, _code, _path) # @private
8
+ @message, @code, @path = _message, _code, _path
9
+ end
10
+
11
+ end
12
+
13
+ end
@@ -0,0 +1,37 @@
1
+ module CircleCi
2
+
3
+ class Response
4
+
5
+ attr_reader :success, :body, :errors, :code, :path
6
+ ##
7
+ # Initializing response object to be returned from API calls, used internally.
8
+ #
9
+ # @private
10
+
11
+ def initialize(http, _code, _path) # @private
12
+ @success, @body, @errors = http.success, http.response, http.errors
13
+ @code, @path, @params = _code, _path
14
+ end
15
+
16
+ ##
17
+ #
18
+ # Convenience method to determine if request was successfull or not
19
+ # @return [Boolean]
20
+
21
+ def success?
22
+ !!@success
23
+ end
24
+
25
+ ##
26
+ #
27
+ # Parses JSON body of request and returns a Hashie::Mash
28
+ # @return [Hashie::Mash]
29
+
30
+ def parsed_body
31
+ return @body if @body.is_a?(Array)
32
+ Hashie::Mash.new(@body) rescue {}
33
+ end
34
+
35
+ end
36
+
37
+ end
@@ -0,0 +1,11 @@
1
+ module CircleCi
2
+
3
+ class User
4
+
5
+ def self.me
6
+ CircleCi.http.get '/me'
7
+ end
8
+
9
+ end
10
+
11
+ end
metadata ADDED
@@ -0,0 +1,152 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: circleci
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Chavez
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2013-04-16 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: rest-client
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: 1.6.7
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ! '>='
28
+ - !ruby/object:Gem::Version
29
+ version: 1.6.7
30
+ - !ruby/object:Gem::Dependency
31
+ name: hashie
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ! '>='
36
+ - !ruby/object:Gem::Version
37
+ version: 1.2.0
38
+ type: :runtime
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: 1.2.0
46
+ - !ruby/object:Gem::Dependency
47
+ name: rspec
48
+ requirement: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ! '>='
52
+ - !ruby/object:Gem::Version
53
+ version: '2.0'
54
+ type: :development
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ! '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '2.0'
62
+ - !ruby/object:Gem::Dependency
63
+ name: simplecov
64
+ requirement: !ruby/object:Gem::Requirement
65
+ none: false
66
+ requirements:
67
+ - - ! '>='
68
+ - !ruby/object:Gem::Version
69
+ version: 0.7.1
70
+ type: :development
71
+ prerelease: false
72
+ version_requirements: !ruby/object:Gem::Requirement
73
+ none: false
74
+ requirements:
75
+ - - ! '>='
76
+ - !ruby/object:Gem::Version
77
+ version: 0.7.1
78
+ - !ruby/object:Gem::Dependency
79
+ name: vcr
80
+ requirement: !ruby/object:Gem::Requirement
81
+ none: false
82
+ requirements:
83
+ - - ! '>='
84
+ - !ruby/object:Gem::Version
85
+ version: 2.2.5
86
+ type: :development
87
+ prerelease: false
88
+ version_requirements: !ruby/object:Gem::Requirement
89
+ none: false
90
+ requirements:
91
+ - - ! '>='
92
+ - !ruby/object:Gem::Version
93
+ version: 2.2.5
94
+ - !ruby/object:Gem::Dependency
95
+ name: webmock
96
+ requirement: !ruby/object:Gem::Requirement
97
+ none: false
98
+ requirements:
99
+ - - ! '>='
100
+ - !ruby/object:Gem::Version
101
+ version: 1.8.11
102
+ type: :development
103
+ prerelease: false
104
+ version_requirements: !ruby/object:Gem::Requirement
105
+ none: false
106
+ requirements:
107
+ - - ! '>='
108
+ - !ruby/object:Gem::Version
109
+ version: 1.8.11
110
+ description: Wraps Circle CI API calls in a gem.
111
+ email: ''
112
+ executables: []
113
+ extensions: []
114
+ extra_rdoc_files:
115
+ - README.md
116
+ files:
117
+ - lib/circleci/build.rb
118
+ - lib/circleci/config.rb
119
+ - lib/circleci/http.rb
120
+ - lib/circleci/project.rb
121
+ - lib/circleci/request_error.rb
122
+ - lib/circleci/response.rb
123
+ - lib/circleci/user.rb
124
+ - lib/circleci.rb
125
+ - README.md
126
+ homepage: http://github.com/mtchavez/circleci
127
+ licenses: []
128
+ post_install_message:
129
+ rdoc_options:
130
+ - --charset=UTF-8 --main=README.md
131
+ require_paths:
132
+ - lib
133
+ required_ruby_version: !ruby/object:Gem::Requirement
134
+ none: false
135
+ requirements:
136
+ - - ! '>='
137
+ - !ruby/object:Gem::Version
138
+ version: '0'
139
+ required_rubygems_version: !ruby/object:Gem::Requirement
140
+ none: false
141
+ requirements:
142
+ - - ! '>='
143
+ - !ruby/object:Gem::Version
144
+ version: '0'
145
+ requirements: []
146
+ rubyforge_project:
147
+ rubygems_version: 1.8.25
148
+ signing_key:
149
+ specification_version: 3
150
+ summary: Circle CI API Wrapper
151
+ test_files: []
152
+ has_rdoc: