semaphore_client 2.0.6

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: 74c748aca6ba0c16ab74c95e812017003632af6d
4
+ data.tar.gz: 30ed1fe21c3ea0795ed709e546057a530e937e91
5
+ SHA512:
6
+ metadata.gz: cf19bf07dac76267008db3d852128b8114d321cacbdcd8275bd2e07a73cd57be37053cdcd338a0d2a60fd4fef42abce84ec581edd41b839affab2e62c663311e
7
+ data.tar.gz: 44c0729c1bd613bb74600ac0aed0a24a150b68f941627041fb88c887165579dd3d355d127bff427360e990cc52469403c205b701a95e7c0c1d903fe2fe7acd6c
data/.gitignore ADDED
@@ -0,0 +1,11 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
9
+
10
+ .rspec_status
11
+ .byebug_history
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --color
@@ -0,0 +1,74 @@
1
+ # Contributor Covenant Code of Conduct
2
+
3
+ ## Our Pledge
4
+
5
+ In the interest of fostering an open and welcoming environment, we as
6
+ contributors and maintainers pledge to making participation in our project and
7
+ our community a harassment-free experience for everyone, regardless of age, body
8
+ size, disability, ethnicity, gender identity and expression, level of experience,
9
+ nationality, personal appearance, race, religion, or sexual identity and
10
+ orientation.
11
+
12
+ ## Our Standards
13
+
14
+ Examples of behavior that contributes to creating a positive environment
15
+ include:
16
+
17
+ * Using welcoming and inclusive language
18
+ * Being respectful of differing viewpoints and experiences
19
+ * Gracefully accepting constructive criticism
20
+ * Focusing on what is best for the community
21
+ * Showing empathy towards other community members
22
+
23
+ Examples of unacceptable behavior by participants include:
24
+
25
+ * The use of sexualized language or imagery and unwelcome sexual attention or
26
+ advances
27
+ * Trolling, insulting/derogatory comments, and personal or political attacks
28
+ * Public or private harassment
29
+ * Publishing others' private information, such as a physical or electronic
30
+ address, without explicit permission
31
+ * Other conduct which could reasonably be considered inappropriate in a
32
+ professional setting
33
+
34
+ ## Our Responsibilities
35
+
36
+ Project maintainers are responsible for clarifying the standards of acceptable
37
+ behavior and are expected to take appropriate and fair corrective action in
38
+ response to any instances of unacceptable behavior.
39
+
40
+ Project maintainers have the right and responsibility to remove, edit, or
41
+ reject comments, commits, code, wiki edits, issues, and other contributions
42
+ that are not aligned to this Code of Conduct, or to ban temporarily or
43
+ permanently any contributor for other behaviors that they deem inappropriate,
44
+ threatening, offensive, or harmful.
45
+
46
+ ## Scope
47
+
48
+ This Code of Conduct applies both within project spaces and in public spaces
49
+ when an individual is representing the project or its community. Examples of
50
+ representing a project or community include using an official project e-mail
51
+ address, posting via an official social media account, or acting as an appointed
52
+ representative at an online or offline event. Representation of a project may be
53
+ further defined and clarified by project maintainers.
54
+
55
+ ## Enforcement
56
+
57
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be
58
+ reported by contacting the project team at jivanovic@renderedtext.com. All
59
+ complaints will be reviewed and investigated and will result in a response that
60
+ is deemed necessary and appropriate to the circumstances. The project team is
61
+ obligated to maintain confidentiality with regard to the reporter of an incident.
62
+ Further details of specific enforcement policies may be posted separately.
63
+
64
+ Project maintainers who do not follow or enforce the Code of Conduct in good
65
+ faith may face temporary or permanent repercussions as determined by other
66
+ members of the project's leadership.
67
+
68
+ ## Attribution
69
+
70
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
71
+ available at [http://contributor-covenant.org/version/1/4][version]
72
+
73
+ [homepage]: http://contributor-covenant.org
74
+ [version]: http://contributor-covenant.org/version/1/4/
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in semaphore_client.gemspec
4
+ gemspec
data/Gemfile.lock ADDED
@@ -0,0 +1,41 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ semaphore_client (2.0.6)
5
+ faraday
6
+
7
+ GEM
8
+ remote: https://rubygems.org/
9
+ specs:
10
+ byebug (9.0.6)
11
+ diff-lcs (1.3)
12
+ faraday (0.12.1)
13
+ multipart-post (>= 1.2, < 3)
14
+ multipart-post (2.0.0)
15
+ rake (10.5.0)
16
+ rspec (3.6.0)
17
+ rspec-core (~> 3.6.0)
18
+ rspec-expectations (~> 3.6.0)
19
+ rspec-mocks (~> 3.6.0)
20
+ rspec-core (3.6.0)
21
+ rspec-support (~> 3.6.0)
22
+ rspec-expectations (3.6.0)
23
+ diff-lcs (>= 1.2.0, < 2.0)
24
+ rspec-support (~> 3.6.0)
25
+ rspec-mocks (3.6.0)
26
+ diff-lcs (>= 1.2.0, < 2.0)
27
+ rspec-support (~> 3.6.0)
28
+ rspec-support (3.6.0)
29
+
30
+ PLATFORMS
31
+ ruby
32
+
33
+ DEPENDENCIES
34
+ bundler (~> 1.14)
35
+ byebug
36
+ rake (~> 10.0)
37
+ rspec (~> 3.0)
38
+ semaphore_client!
39
+
40
+ BUNDLED WITH
41
+ 1.14.6
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2017 Jovan Ivanović
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
+ # SemaphoreClient
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/semaphore_client`. 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 'semaphore_client'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ $ bundle
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install semaphore_client
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]/semaphore_client. 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,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "semaphore_client"
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,64 @@
1
+ require "json"
2
+
3
+ require "semaphore_client/version"
4
+ require "semaphore_client/exceptions"
5
+ require "semaphore_client/http_client"
6
+ require "semaphore_client/model/user"
7
+ require "semaphore_client/model/org"
8
+ require "semaphore_client/model/team"
9
+ require "semaphore_client/model/project"
10
+ require "semaphore_client/model/shared_config"
11
+ require "semaphore_client/model/env_var"
12
+ require "semaphore_client/model/config_file"
13
+ require "semaphore_client/api/user"
14
+ require "semaphore_client/api/org"
15
+ require "semaphore_client/api/team"
16
+ require "semaphore_client/api/project"
17
+ require "semaphore_client/api/shared_config"
18
+ require "semaphore_client/api/env_var"
19
+ require "semaphore_client/api/config_file"
20
+
21
+ class SemaphoreClient
22
+ API_URL = "https://api.semaphoreci.com"
23
+ API_VERSION = "v2"
24
+
25
+ def initialize(auth_token, api_url = API_URL, api_version = API_VERSION)
26
+ @auth_token = auth_token
27
+ @api_url = api_url
28
+ @api_version = api_version
29
+ end
30
+
31
+ def users
32
+ @user_api ||= SemaphoreClient::Api::User.new(http_client)
33
+ end
34
+
35
+ def orgs
36
+ @org_api ||= SemaphoreClient::Api::Org.new(http_client)
37
+ end
38
+
39
+ def teams
40
+ @team_api ||= SemaphoreClient::Api::Team.new(http_client)
41
+ end
42
+
43
+ def projects
44
+ @project_api ||= SemaphoreClient::Api::Project.new(http_client)
45
+ end
46
+
47
+ def shared_configs
48
+ @shared_config_api ||= SemaphoreClient::Api::SharedConfig.new(http_client)
49
+ end
50
+
51
+ def env_vars
52
+ @env_var_api ||= SemaphoreClient::Api::EnvVar.new(http_client)
53
+ end
54
+
55
+ def config_files
56
+ @config_file_api ||= SemaphoreClient::Api::ConfigFile.new(http_client)
57
+ end
58
+
59
+ private
60
+
61
+ def http_client
62
+ @http_client ||= SemaphoreClient::HttpClient.new(@auth_token, @api_url, @api_version)
63
+ end
64
+ end
@@ -0,0 +1,129 @@
1
+ class SemaphoreClient
2
+ module Api
3
+ class ConfigFile
4
+ def initialize(http_client)
5
+ @http_client = http_client
6
+ end
7
+
8
+ def list_for_project(project_id)
9
+ list_for_project!(project_id)
10
+ rescue SemaphoreClient::Exceptions::RequestFailed
11
+ end
12
+
13
+ def attach_to_project(config_file_id, project_id)
14
+ attach_to_project!(config_file_id, project_id)
15
+ rescue SemaphoreClient::Exceptions::RequestFailed
16
+ end
17
+
18
+ def detach_from_project(config_file_id, project_id)
19
+ detach_from_project!(config_file_id, project_id)
20
+ rescue SemaphoreClient::Exceptions::RequestFailed
21
+ end
22
+
23
+ def list_for_shared_config(shared_config_id)
24
+ list_for_shared_config!(shared_config_id)
25
+ rescue SemaphoreClient::Exceptions::RequestFailed
26
+ end
27
+
28
+ def create_for_shared_config(shared_config_id, params)
29
+ create_for_shared_config!(shared_config_id, params)
30
+ rescue SemaphoreClient::Exceptions::RequestFailed
31
+ end
32
+
33
+ def get(id)
34
+ get!(id)
35
+ rescue SemaphoreClient::Exceptions::RequestFailed
36
+ end
37
+
38
+ def delete(id)
39
+ delete!(id)
40
+ rescue SemaphoreClient::Exceptions::RequestFailed
41
+ end
42
+
43
+ def update(id, params)
44
+ update!(id, params)
45
+ rescue SemaphoreClient::Exceptions::RequestFailed
46
+ end
47
+
48
+ def list_for_project!(project_id)
49
+ response = @http_client.get([:projects, project_id, :config_files])
50
+
51
+ assert_response_status(response, 200)
52
+
53
+ content = JSON.parse(response.body)
54
+
55
+ content.map do |entity|
56
+ SemaphoreClient::Model::ConfigFile.load(entity)
57
+ end
58
+ end
59
+
60
+ def attach_to_project!(config_file_id, project_id)
61
+ response = @http_client.post([:projects, project_id, :config_files, config_file_id])
62
+
63
+ assert_response_status(response, 204)
64
+ end
65
+
66
+ def detach_from_project!(config_file_id, project_id)
67
+ response = @http_client.delete([:projects, project_id, :config_files, config_file_id])
68
+
69
+ assert_response_status(response, 204)
70
+ end
71
+
72
+ def list_for_shared_config!(shared_config_id)
73
+ response = @http_client.get([:shared_configs, shared_config_id, :config_files])
74
+
75
+ assert_response_status(response, 200)
76
+
77
+ content = JSON.parse(response.body)
78
+
79
+ content.map do |entity|
80
+ SemaphoreClient::Model::ConfigFile.load(entity)
81
+ end
82
+ end
83
+
84
+ def create_for_shared_config!(shared_config_id, params)
85
+ response = @http_client.post([:shared_configs, shared_config_id, :config_files], params.to_json)
86
+
87
+ assert_response_status(response, 200)
88
+
89
+ content = JSON.parse(response.body)
90
+
91
+ SemaphoreClient::Model::ConfigFile.load(content)
92
+ end
93
+
94
+ def get!(id)
95
+ response = @http_client.get([:config_files, id])
96
+
97
+ assert_response_status(response, 200)
98
+
99
+ content = JSON.parse(response.body)
100
+
101
+ SemaphoreClient::Model::ConfigFile.load(content)
102
+ end
103
+
104
+ def delete!(id)
105
+ response = @http_client.delete([:config_files, id])
106
+
107
+ assert_response_status(response, 200)
108
+ end
109
+
110
+ def update!(id, params)
111
+ response = @http_client.patch([:config_files, id], params.to_json)
112
+
113
+ assert_response_status(response, 200)
114
+
115
+ content = JSON.parse(response.body)
116
+
117
+ SemaphoreClient::Model::ConfigFile.load(content)
118
+ end
119
+
120
+ private
121
+
122
+ def assert_response_status(response, expected_status)
123
+ return if response.status == expected_status
124
+
125
+ raise SemaphoreClient::Exceptions::RequestFailed, response.status
126
+ end
127
+ end
128
+ end
129
+ end
@@ -0,0 +1,129 @@
1
+ class SemaphoreClient
2
+ module Api
3
+ class EnvVar
4
+ def initialize(http_client)
5
+ @http_client = http_client
6
+ end
7
+
8
+ def list_for_project(project_id)
9
+ list_for_project!(project_id)
10
+ rescue SemaphoreClient::Exceptions::RequestFailed
11
+ end
12
+
13
+ def attach_to_project(env_var_id, project_id)
14
+ attach_to_project!(env_var_id, project_id)
15
+ rescue SemaphoreClient::Exceptions::RequestFailed
16
+ end
17
+
18
+ def detach_from_project(env_var_id, project_id)
19
+ detach_from_project!(env_var_id, project_id)
20
+ rescue SemaphoreClient::Exceptions::RequestFailed
21
+ end
22
+
23
+ def list_for_shared_config(shared_config_id)
24
+ list_for_shared_config!(shared_config_id)
25
+ rescue SemaphoreClient::Exceptions::RequestFailed
26
+ end
27
+
28
+ def create_for_shared_config(shared_config_id, params)
29
+ create_for_shared_config!(shared_config_id, params)
30
+ rescue SemaphoreClient::Exceptions::RequestFailed
31
+ end
32
+
33
+ def get(id)
34
+ get!(id)
35
+ rescue SemaphoreClient::Exceptions::RequestFailed
36
+ end
37
+
38
+ def delete(id)
39
+ delete!(id)
40
+ rescue SemaphoreClient::Exceptions::RequestFailed
41
+ end
42
+
43
+ def update(id, params)
44
+ update!(id, params)
45
+ rescue SemaphoreClient::Exceptions::RequestFailed
46
+ end
47
+
48
+ def list_for_project!(project_id)
49
+ response = @http_client.get([:projects, project_id, :env_vars])
50
+
51
+ assert_response_status(response, 200)
52
+
53
+ content = JSON.parse(response.body)
54
+
55
+ content.map do |entity|
56
+ SemaphoreClient::Model::EnvVar.load(entity)
57
+ end
58
+ end
59
+
60
+ def attach_to_project!(env_var_id, project_id)
61
+ response = @http_client.post([:projects, project_id, :env_vars, env_var_id])
62
+
63
+ assert_response_status(response, 204)
64
+ end
65
+
66
+ def detach_from_project!(env_var_id, project_id)
67
+ response = @http_client.delete([:projects, project_id, :env_vars, env_var_id])
68
+
69
+ assert_response_status(response, 204)
70
+ end
71
+
72
+ def list_for_shared_config!(shared_config_id)
73
+ response = @http_client.get([:shared_configs, shared_config_id, :env_vars])
74
+
75
+ assert_response_status(response, 200)
76
+
77
+ content = JSON.parse(response.body)
78
+
79
+ content.map do |entity|
80
+ SemaphoreClient::Model::EnvVar.load(entity)
81
+ end
82
+ end
83
+
84
+ def create_for_shared_config!(shared_config_id, params)
85
+ response = @http_client.post([:shared_configs, shared_config_id, :env_vars], params.to_json)
86
+
87
+ assert_response_status(response, 200)
88
+
89
+ content = JSON.parse(response.body)
90
+
91
+ SemaphoreClient::Model::EnvVar.load(content)
92
+ end
93
+
94
+ def get!(id)
95
+ response = @http_client.get([:env_vars, id])
96
+
97
+ assert_response_status(response, 200)
98
+
99
+ content = JSON.parse(response.body)
100
+
101
+ SemaphoreClient::Model::EnvVar.load(content)
102
+ end
103
+
104
+ def delete!(id)
105
+ response = @http_client.delete([:env_vars, id])
106
+
107
+ assert_response_status(response, 200)
108
+ end
109
+
110
+ def update!(id, params)
111
+ response = @http_client.patch([:env_vars, id], params.to_json)
112
+
113
+ assert_response_status(response, 200)
114
+
115
+ content = JSON.parse(response.body)
116
+
117
+ SemaphoreClient::Model::EnvVar.load(content)
118
+ end
119
+
120
+ private
121
+
122
+ def assert_response_status(response, expected_status)
123
+ return if response.status == expected_status
124
+
125
+ raise SemaphoreClient::Exceptions::RequestFailed, response.status
126
+ end
127
+ end
128
+ end
129
+ end