lolp 0.2.1 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +1 -1
- data/Gemfile +5 -0
- data/Rakefile +4 -0
- data/bin/console +7 -0
- data/lib/lolp.rb +0 -1
- data/lib/lolp/client.rb +11 -4
- data/lib/lolp/client/authentication.rb +12 -0
- data/lib/lolp/client/project.rb +29 -0
- data/lib/lolp/configuration.rb +7 -12
- data/lib/lolp/connection.rb +54 -19
- data/lib/lolp/errors.rb +54 -0
- data/lib/lolp/version.rb +1 -1
- metadata +7 -4
- data/lib/lolp/project.rb +0 -23
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 48f64d7c464aa54df35fa07f1fbd58c1aa48a09d
|
4
|
+
data.tar.gz: 520ceff36e7affc10c78a5b3ca98d392b6e5557f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8d743865d68e6a667b5e808d580c2bc73e788baaec23e1f9156c3792177bd55fffd7068a72e2198a2dccced2e450fb635fd6438aa846da7037116d1241fd5f76
|
7
|
+
data.tar.gz: e34ba0f0aa017fa03fe3caf33a461148ebd8b1d39dcac4b96500a3fd41dad0338d94c25bd37e076fe73df5f3cc5d11bb82d2a0ceb0811ae0409301e2618ea20b
|
data/.travis.yml
CHANGED
data/Gemfile
CHANGED
data/Rakefile
CHANGED
data/bin/console
ADDED
data/lib/lolp.rb
CHANGED
data/lib/lolp/client.rb
CHANGED
@@ -1,14 +1,21 @@
|
|
1
1
|
require 'lolp/connection'
|
2
|
-
require 'lolp/project'
|
3
2
|
require 'lolp/configuration'
|
3
|
+
require 'lolp/client/project'
|
4
|
+
require 'lolp/client/authentication'
|
4
5
|
|
5
6
|
module Lolp
|
6
7
|
class Client
|
7
|
-
include Lolp::Project
|
8
8
|
include Lolp::Configuration
|
9
|
+
include Lolp::Connection
|
10
|
+
include Lolp::Client::Project
|
11
|
+
include Lolp::Client::Authentication
|
9
12
|
|
10
|
-
def
|
11
|
-
|
13
|
+
def initialize(config = {})
|
14
|
+
defaults
|
15
|
+
|
16
|
+
config.each do |k,v|
|
17
|
+
instance_variable_set(:"@#{key}", v)
|
18
|
+
end
|
12
19
|
end
|
13
20
|
end
|
14
21
|
end
|
@@ -0,0 +1,12 @@
|
|
1
|
+
module Lolp
|
2
|
+
class Client
|
3
|
+
module Authentication
|
4
|
+
def authenticate(username = nil, password = nil)
|
5
|
+
@token = post('v1/authenticate',
|
6
|
+
username: username || @username,
|
7
|
+
password: password || @password)
|
8
|
+
end
|
9
|
+
alias login authenticate
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
module Lolp
|
2
|
+
class Client
|
3
|
+
module Project
|
4
|
+
def projects
|
5
|
+
get('v1/projects')
|
6
|
+
end
|
7
|
+
|
8
|
+
def project(name)
|
9
|
+
get("v1/projects/#{name}")
|
10
|
+
end
|
11
|
+
|
12
|
+
def create_project(type, params = {})
|
13
|
+
post('v1/projects', params.merge(type: type))
|
14
|
+
end
|
15
|
+
|
16
|
+
def delete_project(name)
|
17
|
+
delete("v1/projects/#{name}")
|
18
|
+
end
|
19
|
+
|
20
|
+
def create_custom_domain(domain, custom_domain)
|
21
|
+
post("v1/projects/#{domain}/custom-domains", domain: custom_domain)
|
22
|
+
end
|
23
|
+
|
24
|
+
def delete_custom_domain(domain, custom_domain)
|
25
|
+
delete("v1/projects/#{domain}/custom-domains/#{custom_domain}")
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
data/lib/lolp/configuration.rb
CHANGED
@@ -1,21 +1,16 @@
|
|
1
1
|
module Lolp
|
2
2
|
module Configuration
|
3
|
-
|
4
|
-
@config ||= Config.new
|
5
|
-
end
|
3
|
+
attr_accessor :api_endpoint, :username, :password, :token
|
6
4
|
|
7
5
|
def configure
|
8
|
-
yield
|
6
|
+
yield self
|
9
7
|
end
|
10
8
|
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
@username = ENV['LOLIPOP_MC_USERNAME']
|
17
|
-
@password = ENV['LOLIPOP_MC_PASSWORD']
|
18
|
-
end
|
9
|
+
def defaults
|
10
|
+
@api_endpoint = ENV['LOLIPOP_MC_API_ENDPOINT'] || 'https://api.mc.lolipop.jp/'
|
11
|
+
@username = ENV['LOLIPOP_MC_USERNAME']
|
12
|
+
@password = ENV['LOLIPOP_MC_PASSWORD']
|
13
|
+
@token = ENV['LOLIPOP_MC_TOKEN']
|
19
14
|
end
|
20
15
|
end
|
21
16
|
end
|
data/lib/lolp/connection.rb
CHANGED
@@ -1,38 +1,73 @@
|
|
1
1
|
require 'faraday'
|
2
|
+
require 'lolp/errors'
|
2
3
|
require 'faraday_middleware'
|
3
4
|
|
4
5
|
module Lolp
|
5
|
-
|
6
|
-
def
|
7
|
-
|
8
|
-
authenticate
|
9
|
-
@connection = connection
|
10
|
-
end
|
11
|
-
|
12
|
-
def get(path)
|
13
|
-
@connection.get(path)
|
6
|
+
module Connection
|
7
|
+
def get(path, params = {})
|
8
|
+
request(:get, path, params)
|
14
9
|
end
|
15
10
|
|
16
11
|
def post(path, params = {})
|
17
|
-
|
12
|
+
request(:post, path, params)
|
18
13
|
end
|
19
14
|
|
20
15
|
def delete(path, params = {})
|
21
|
-
|
16
|
+
request(:delete, path, params)
|
22
17
|
end
|
23
18
|
|
24
|
-
|
19
|
+
def authenticated?
|
20
|
+
!!@token
|
21
|
+
end
|
25
22
|
|
26
|
-
def
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
23
|
+
def last_response
|
24
|
+
@last_response if defined? @last_response
|
25
|
+
end
|
26
|
+
|
27
|
+
def auto_loginable?(url)
|
28
|
+
!authenticated? && url !~ /\/authenticate/ && @username && @password
|
29
|
+
end
|
30
|
+
|
31
|
+
def request(method, url = nil, data = nil, headers = nil, &block)
|
32
|
+
login if auto_loginable?(url)
|
33
|
+
|
34
|
+
@last_response = if %i(post put patch).include?(method)
|
35
|
+
connection.run_request(method, url, data, headers, &block)
|
36
|
+
else
|
37
|
+
connection.run_request(method, url, nil, headers) { |r|
|
38
|
+
r.params.update(data) if data
|
39
|
+
yield(r) if block_given?
|
40
|
+
}
|
41
|
+
end
|
42
|
+
|
43
|
+
if error = Error.from_response(@last_response)
|
44
|
+
raise error
|
31
45
|
end
|
46
|
+
@last_response.body
|
32
47
|
end
|
33
48
|
|
34
|
-
|
35
|
-
|
49
|
+
private
|
50
|
+
|
51
|
+
def connection
|
52
|
+
project_url = 'https://github.com/pepabo/lolp.rb'
|
53
|
+
user_agent = "lolp/#{VERSION} (+#{project_url}; ruby#{RUBY_VERSION})"
|
54
|
+
ssl_verify = true
|
55
|
+
|
56
|
+
args = {
|
57
|
+
url: @api_endpoint,
|
58
|
+
ssl: { verify: ssl_verify },
|
59
|
+
headers: {
|
60
|
+
user_agent: user_agent,
|
61
|
+
content_type: 'application/json'
|
62
|
+
}
|
63
|
+
}
|
64
|
+
|
65
|
+
@connection.authorization(:Bearer, @token) if @connection && authenticated?
|
66
|
+
@connection ||= Faraday.new(args) do |f|
|
67
|
+
f.request :json
|
68
|
+
f.response :json, content_type: /\bjson$/
|
69
|
+
f.adapter Faraday.default_adapter
|
70
|
+
end
|
36
71
|
end
|
37
72
|
end
|
38
73
|
end
|
data/lib/lolp/errors.rb
ADDED
@@ -0,0 +1,54 @@
|
|
1
|
+
module Lolp
|
2
|
+
class Error < StandardError
|
3
|
+
class << self
|
4
|
+
def from_response(r)
|
5
|
+
if klass = case r.status.to_i
|
6
|
+
when 400 then BadRequest
|
7
|
+
when 401 then Unauthorized
|
8
|
+
when 402 then PaymentRequired
|
9
|
+
when 403 then Forbidden
|
10
|
+
when 404 then NotFound
|
11
|
+
when 406 then NotAcceptable
|
12
|
+
when 409 then Conflict
|
13
|
+
when 429 then TooManyRequests
|
14
|
+
when 422 then UnprocessableEntity
|
15
|
+
when 400..499 then ClientError
|
16
|
+
when 500 then InternalServerError
|
17
|
+
when 501 then NotImplemented
|
18
|
+
when 502 then BadGateway
|
19
|
+
when 503 then ServiceUnavailable
|
20
|
+
when 500..599 then ServerError
|
21
|
+
end
|
22
|
+
klass.new(build_error_message(r))
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
def build_error_message(res = nil)
|
27
|
+
return nil if res.nil?
|
28
|
+
message = "#{res.env.method.to_s.upcase} "
|
29
|
+
message << "#{res.env.url}: "
|
30
|
+
message << "#{res.status} - "
|
31
|
+
message << "#{res.body}" if res.body
|
32
|
+
message
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
class BadRequest < Error; end
|
38
|
+
class Unauthorized < Error; end
|
39
|
+
class PaymentRequired < Error; end
|
40
|
+
class Forbidden < Error; end
|
41
|
+
class NotFound < Error; end
|
42
|
+
class NotAcceptable < Error; end
|
43
|
+
class Conflict < Error; end
|
44
|
+
class TooManyRequests; end
|
45
|
+
class UnprocessableEntity < Error; end
|
46
|
+
class ClientError < Error; end
|
47
|
+
|
48
|
+
class InternalServerError < Error; end
|
49
|
+
class NotImplemented < Error; end
|
50
|
+
class BadGateway < Error; end
|
51
|
+
class ServiceUnavailable < Error; end
|
52
|
+
class ServerError < Error; end
|
53
|
+
end
|
54
|
+
|
data/lib/lolp/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: lolp
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- linyows
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2018-04-12 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -135,11 +135,14 @@ files:
|
|
135
135
|
- Gemfile
|
136
136
|
- README.md
|
137
137
|
- Rakefile
|
138
|
+
- bin/console
|
138
139
|
- lib/lolp.rb
|
139
140
|
- lib/lolp/client.rb
|
141
|
+
- lib/lolp/client/authentication.rb
|
142
|
+
- lib/lolp/client/project.rb
|
140
143
|
- lib/lolp/configuration.rb
|
141
144
|
- lib/lolp/connection.rb
|
142
|
-
- lib/lolp/
|
145
|
+
- lib/lolp/errors.rb
|
143
146
|
- lib/lolp/version.rb
|
144
147
|
- lolp.gemspec
|
145
148
|
homepage: https://lolipop.jp
|
@@ -161,7 +164,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
161
164
|
version: '0'
|
162
165
|
requirements: []
|
163
166
|
rubyforge_project:
|
164
|
-
rubygems_version: 2.6.
|
167
|
+
rubygems_version: 2.6.14
|
165
168
|
signing_key:
|
166
169
|
specification_version: 4
|
167
170
|
summary: The lolipop! client
|
data/lib/lolp/project.rb
DELETED
@@ -1,23 +0,0 @@
|
|
1
|
-
module Lolp
|
2
|
-
module Project
|
3
|
-
def projects
|
4
|
-
connection.get('projects')
|
5
|
-
end
|
6
|
-
|
7
|
-
def create_project(type, params = {})
|
8
|
-
connection.post('projects', params.merge(type: type))
|
9
|
-
end
|
10
|
-
|
11
|
-
def delete_project(name)
|
12
|
-
connection.delete("projects/#{name}")
|
13
|
-
end
|
14
|
-
|
15
|
-
def create_custom_domain(domain, custom_domain)
|
16
|
-
connection.post("projects/#{domain}/custom-domains", domain: custom_domain)
|
17
|
-
end
|
18
|
-
|
19
|
-
def delete_custom_domain(domain, custom_domain)
|
20
|
-
connection.delete("projects/#{domain}/custom-domains/#{custom_domain}")
|
21
|
-
end
|
22
|
-
end
|
23
|
-
end
|