wercker_api 0.1.1.pre6

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: 49f45cd407d38ab387b9887b6c7de089a04ea9f0
4
+ data.tar.gz: ed8077c09d0553ad081927cff1af5157f0a969a2
5
+ SHA512:
6
+ metadata.gz: 467ff5fd6511b062fd1868b303a1bdb24e238446eb9f96ef5b348a35b8cd6c32828394456aa9031fc7e3423380d8f13ef739159772b28c3d95c0d73b6b67db52
7
+ data.tar.gz: 1851df6f3dd66a27793869a516ad8f62be62418b3fe40d805b67414083ddca78f0033a10f5271cf1aa79df085a2343166c601854097e7e91e58b9d253f2ed694
data/.gitignore ADDED
@@ -0,0 +1,15 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+
11
+ # rspec failure tracking
12
+ .rspec_status
13
+ .wercker
14
+ .byebug_history
15
+ .envrc
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --backtrace
data/.travis.yml ADDED
@@ -0,0 +1,5 @@
1
+ sudo: false
2
+ language: ruby
3
+ rvm:
4
+ - 2.4.1
5
+ before_install: gem install bundler -v 1.15.1
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source "https://rubygems.org"
2
+ ruby '2.4.1'
3
+ # Specify your gem's dependencies in wercker_api.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2017 yann marquet
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,39 @@
1
+ # WerckerApi
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/wercker_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 'wercker_api'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ $ bundle
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install wercker_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 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]/wercker_api.
36
+
37
+ ## License
38
+
39
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
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,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "wercker_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(__FILE__)
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,8 @@
1
+ module WerckerAPI
2
+ class Application
3
+ class Build
4
+ INDEX = -> (version, user_name, application) { "/api/#{version}/applications/#{user_name}/#{application}/builds" }
5
+
6
+ end
7
+ end
8
+ end
@@ -0,0 +1,17 @@
1
+ module WerckerAPI
2
+ class Application
3
+ class BuildCollection
4
+ include Enumerable
5
+ def initialize(collection = [])
6
+ self.collection = collection
7
+ end
8
+
9
+ def each
10
+ collection.each
11
+ end
12
+
13
+ private
14
+ attr_accessor :collection
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,86 @@
1
+ module WerckerAPI
2
+ class Meta
3
+ include Virtus.model
4
+ attribute :username, String
5
+ attribute :type, String
6
+ attribute :werckerEmployee, Boolean
7
+
8
+ def wercker_employee
9
+ werckerEmployee
10
+ end
11
+ end
12
+
13
+ class Avatar
14
+ include Virtus.model
15
+ attribute :gravatar, String
16
+
17
+ end
18
+ class Owner
19
+ include Virtus.model
20
+ attribute :type, String
21
+ attribute :userId, String
22
+ attribute :name, String
23
+ attribute :avatar, Avatar
24
+ attribute :meta, Meta
25
+
26
+ def user_id
27
+ userId
28
+ end
29
+ end
30
+
31
+ class SCM
32
+ include Virtus.model
33
+ attribute :type, String
34
+ attribute :owner, String
35
+ attribute :domain, String
36
+ attribute :repository, String
37
+ end
38
+
39
+ class Settings
40
+ include Virtus.model
41
+ attribute :privacy, String
42
+ attribute :stack, Integer
43
+ attribute :ignoredBranches, Array[String]
44
+
45
+ def ignored_branches
46
+ ignoredBranches
47
+ end
48
+ end
49
+
50
+ class Application
51
+ INDEX = -> (version, username) { "/api/#{version}/applications/#{username}" }
52
+ SHOW = -> (version, username, application) { "/api/#{version}/applications/#{username}/#{application}" }
53
+
54
+ include Virtus.model
55
+ attribute :id, String
56
+ attribute :url, String
57
+ attribute :name, String
58
+ attribute :owner, Owner
59
+ attribute :builds, String
60
+ attribute :deploys, String
61
+ attribute :scm, SCM
62
+ attribute :badgeKey, String
63
+ attribute :createdAt, Time
64
+ attribute :updatedAt, Time
65
+ attribute :allowedActions, Array[String]
66
+ attribute :theme, String
67
+ attribute :settings, Settings
68
+
69
+ def badge_key
70
+ badgeKey
71
+ end
72
+
73
+ def created_at
74
+ createdAt
75
+ end
76
+
77
+ def updated_at
78
+ updatedAt
79
+ end
80
+
81
+ def allowed_actions
82
+ allowedActions
83
+ end
84
+
85
+ end
86
+ end
@@ -0,0 +1,17 @@
1
+ module WerckerAPI
2
+ class ApplicationCollection
3
+
4
+ include Enumerable
5
+
6
+ def initialize(collection = [])
7
+ self.collection = collection.map { |item| WerckerAPI::Application.new(item) }
8
+ end
9
+
10
+ def each
11
+ collection.each
12
+ end
13
+
14
+ private
15
+ attr_accessor :collection
16
+ end
17
+ end
@@ -0,0 +1,100 @@
1
+ require 'net/http'
2
+ require 'json'
3
+ module WerckerAPI
4
+
5
+ class WerckerAPI::Error < ArgumentError
6
+ def initialize(response)
7
+ json = JSON.parse(response.body)
8
+ msg = <<-EOM
9
+ Error: #{json['error']}, status: #{json['statusCode']}, message: #{json['message']}
10
+ EOM
11
+ super(msg)
12
+ end
13
+ end
14
+
15
+ class Client
16
+
17
+ API_ENDPOINT = URI('https://app.wercker.com').freeze
18
+
19
+ def initialize(token = nil, api_version = 'v3')
20
+ self.api_token = token || ENV['WERCKER_API_TOKEN']
21
+ raise_token_nil_error if api_token.nil?
22
+ self.api_version = api_version
23
+ end
24
+
25
+ def applications(user_name, params = {})
26
+ request build_get_request(Application::INDEX[api_version, user_name], params), ApplicationCollection
27
+ end
28
+
29
+ def application(user_name, application)
30
+ request build_get_request(Application::SHOW[api_version, user_name, application]), Application
31
+ end
32
+
33
+ def update_application(user_name, application, branches)
34
+ request build_put_request(Application::SHOW[api_version, user_name, application], { ignoredBranches: branches }), Application
35
+ end
36
+
37
+ def application_builds(user_name , application)
38
+ request build_get_request(Application::Build::INDEX[api_version, user_name, application]), Application::BuildCollection
39
+ end
40
+
41
+ private
42
+ attr_accessor :api_token, :api_version
43
+
44
+ def http_client
45
+ @http_client ||= build_http_client
46
+ end
47
+
48
+ def raise_token_nil_error
49
+ msg = <<-EOM
50
+ A token is required to communicate with the API, please refer to the read me.
51
+
52
+ client = WerckerAPI::Client.new('2039e0239840239u0239uf0293v2093urbv0293urbv')
53
+
54
+ More inforation at: http://devcenter.wercker.com/docs/api/getting-started/authentication
55
+ EOM
56
+ raise ArgumentError.new(msg)
57
+ end
58
+
59
+ def build_get_request(uri, params = {})
60
+ uri = URI::HTTP.build(path: uri, query: URI.encode_www_form(params))
61
+ authorise_request(Net::HTTP::Get.new(uri))
62
+ end
63
+
64
+ def build_put_request(uri, params)
65
+ request = Net::HTTP::Patch.new(URI::HTTP.build(path: uri))
66
+ request.body = JSON.dump(params)
67
+ request['Content-Type'] = 'application/json'
68
+ authorise_request(request)
69
+ end
70
+
71
+ def authorise_request(request)
72
+ request['Authorization'] = "Bearer #{api_token}"
73
+ request
74
+ end
75
+
76
+ def build_http_client
77
+ http_client = Net::HTTP.new(API_ENDPOINT.host, API_ENDPOINT.port)
78
+ http_client.use_ssl = true
79
+ http_client
80
+ end
81
+
82
+ def request(request, serializer)
83
+ handle(http_client.request(request), serializer)
84
+ end
85
+
86
+ def handle(response, klass)
87
+ case response
88
+ when Net::HTTPSuccess
89
+ klass.new(JSON.parse(response.body))
90
+ else
91
+ handle_error(response)
92
+ end
93
+ end
94
+
95
+ def handle_error(response)
96
+ raise WerckerAPI::Error.new(response)
97
+ end
98
+ end
99
+
100
+ end
@@ -0,0 +1,3 @@
1
+ module WerckerAPI
2
+ VERSION = "0.1.1.pre6"
3
+ end
@@ -0,0 +1,9 @@
1
+ require "virtus"
2
+ require "wercker_api/version"
3
+ require "wercker_api/application"
4
+ require "wercker_api/application_collection"
5
+ require "wercker_api/application/build"
6
+ require "wercker_api/application/build_collection"
7
+ require "wercker_api/client"
8
+
9
+ module WerckerAPI; end
data/wercker.yml ADDED
@@ -0,0 +1,34 @@
1
+ box: ruby:2.4.1
2
+ build:
3
+ steps:
4
+ - bundle-install
5
+ - script:
6
+ name: rspec
7
+ code: bundle exec rspec
8
+ deploy-pre-release:
9
+ steps:
10
+ - bundle-install
11
+ - script:
12
+ name: configure git
13
+ code: |
14
+ git config --global user.email "ymarquet@gmail.com"
15
+ git config --global user.name "StupidCodefactory"
16
+ - add-ssh-key:
17
+ keyname: GITHUB
18
+ # - wercker/add-to-known_hosts@2.0.1:
19
+ # hostname: github.com
20
+ # fingerprint: 4d:de:af:f1:29:53:df:e1:26:f9:92:b9:cc:dc:e3:07
21
+ - script:
22
+ name: configure gem
23
+ code: |
24
+ echo -e "---\n:rubygems_api_key: $GEM_API_KEY\n" >> ~/.gem/credentials
25
+ chmod 0600 ~/.gem/credentials
26
+ - script:
27
+ name: configure bump and tag
28
+ code: |
29
+ cat ~/.gem/credentials
30
+ bundle exec gem bump -v pre -k ~/.gem/credentials
31
+ - script:
32
+ name: configure release
33
+ code: |
34
+ bundle exec gem release -k ~/.gem/credentials -t
@@ -0,0 +1,43 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path("../lib", __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require "wercker_api/version"
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "wercker_api"
8
+ spec.version = WerckerAPI::VERSION
9
+ spec.authors = ["yann marquet"]
10
+ spec.email = ["ymarquet@gmail.com"]
11
+
12
+ spec.summary = %q{interact with wercker API.}
13
+ spec.description = %q{interact with wercker API, Deeper integration with wercker.}
14
+ spec.homepage = "https://github.com/StupidCodeFactory/wercker_api"
15
+ spec.license = "MIT"
16
+
17
+ # Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
18
+ # to allow pushing to a single host or delete this section to allow pushing to any host.
19
+ if spec.respond_to?(:metadata)
20
+ spec.metadata["allowed_push_host"] = 'https://rubygems.org'
21
+ else
22
+ raise "RubyGems 2.0 or newer is required to protect against " \
23
+ "public gem pushes."
24
+ end
25
+
26
+ spec.files = `git ls-files -z`.split("\x0").reject do |f|
27
+ f.match(%r{^(test|spec|features)/})
28
+ end
29
+ spec.bindir = "exe"
30
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
31
+ spec.require_paths = ["lib"]
32
+
33
+ spec.add_dependency 'virtus', '~> 1.0.5'
34
+ spec.add_development_dependency 'bundler', '~> 1.15'
35
+ spec.add_development_dependency 'rake', '~> 10.0'
36
+ spec.add_development_dependency 'rspec', '~> 3.0'
37
+ spec.add_development_dependency 'rspec-collection_matchers', '~> 1.1.3'
38
+ spec.add_development_dependency 'vcr', '~> 3.0.3'
39
+ spec.add_development_dependency 'gem-release', '~> 1.0.0'
40
+ spec.add_development_dependency 'webmock', '~> 3.0.1'
41
+ spec.add_development_dependency 'byebug', '~> 9.0.6'
42
+ spec.add_development_dependency 'awesome_print', '~> 1.8.0'
43
+ end
metadata ADDED
@@ -0,0 +1,203 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: wercker_api
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.1.pre6
5
+ platform: ruby
6
+ authors:
7
+ - yann marquet
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2017-07-03 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: virtus
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: 1.0.5
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: 1.0.5
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.15'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '1.15'
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: rspec
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '3.0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '3.0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rspec-collection_matchers
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: 1.1.3
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: 1.1.3
83
+ - !ruby/object:Gem::Dependency
84
+ name: vcr
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: 3.0.3
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: 3.0.3
97
+ - !ruby/object:Gem::Dependency
98
+ name: gem-release
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - "~>"
102
+ - !ruby/object:Gem::Version
103
+ version: 1.0.0
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - "~>"
109
+ - !ruby/object:Gem::Version
110
+ version: 1.0.0
111
+ - !ruby/object:Gem::Dependency
112
+ name: webmock
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - "~>"
116
+ - !ruby/object:Gem::Version
117
+ version: 3.0.1
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - "~>"
123
+ - !ruby/object:Gem::Version
124
+ version: 3.0.1
125
+ - !ruby/object:Gem::Dependency
126
+ name: byebug
127
+ requirement: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - "~>"
130
+ - !ruby/object:Gem::Version
131
+ version: 9.0.6
132
+ type: :development
133
+ prerelease: false
134
+ version_requirements: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - "~>"
137
+ - !ruby/object:Gem::Version
138
+ version: 9.0.6
139
+ - !ruby/object:Gem::Dependency
140
+ name: awesome_print
141
+ requirement: !ruby/object:Gem::Requirement
142
+ requirements:
143
+ - - "~>"
144
+ - !ruby/object:Gem::Version
145
+ version: 1.8.0
146
+ type: :development
147
+ prerelease: false
148
+ version_requirements: !ruby/object:Gem::Requirement
149
+ requirements:
150
+ - - "~>"
151
+ - !ruby/object:Gem::Version
152
+ version: 1.8.0
153
+ description: interact with wercker API, Deeper integration with wercker.
154
+ email:
155
+ - ymarquet@gmail.com
156
+ executables: []
157
+ extensions: []
158
+ extra_rdoc_files: []
159
+ files:
160
+ - ".gitignore"
161
+ - ".rspec"
162
+ - ".travis.yml"
163
+ - Gemfile
164
+ - LICENSE.txt
165
+ - README.md
166
+ - Rakefile
167
+ - bin/console
168
+ - bin/setup
169
+ - lib/wercker_api.rb
170
+ - lib/wercker_api/application.rb
171
+ - lib/wercker_api/application/build.rb
172
+ - lib/wercker_api/application/build_collection.rb
173
+ - lib/wercker_api/application_collection.rb
174
+ - lib/wercker_api/client.rb
175
+ - lib/wercker_api/version.rb
176
+ - wercker.yml
177
+ - wercker_api.gemspec
178
+ homepage: https://github.com/StupidCodeFactory/wercker_api
179
+ licenses:
180
+ - MIT
181
+ metadata:
182
+ allowed_push_host: https://rubygems.org
183
+ post_install_message:
184
+ rdoc_options: []
185
+ require_paths:
186
+ - lib
187
+ required_ruby_version: !ruby/object:Gem::Requirement
188
+ requirements:
189
+ - - ">="
190
+ - !ruby/object:Gem::Version
191
+ version: '0'
192
+ required_rubygems_version: !ruby/object:Gem::Requirement
193
+ requirements:
194
+ - - ">"
195
+ - !ruby/object:Gem::Version
196
+ version: 1.3.1
197
+ requirements: []
198
+ rubyforge_project:
199
+ rubygems_version: 2.6.11
200
+ signing_key:
201
+ specification_version: 4
202
+ summary: interact with wercker API.
203
+ test_files: []