tilda-simple-api 0.1.1 → 0.2.0
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 +4 -4
- data/README.md +13 -0
- data/lib/tilda/simple/api.rb +1 -0
- data/lib/tilda/simple/api/config.rb +2 -1
- data/lib/tilda/simple/api/errors.rb +3 -9
- data/lib/tilda/simple/api/errors_handler.rb +36 -0
- data/lib/tilda/simple/api/request.rb +43 -46
- data/lib/tilda/simple/api/version.rb +1 -1
- data/tilda-simple-api.gemspec +1 -0
- metadata +4 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1c08f2b15626300a8c3ca48e18ece75485affdad
|
4
|
+
data.tar.gz: 2f64a02a11f40b8365bcaa4f172d57b1fdab541c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ec265f4edfed9ccf4c7cd47aeae0a7ae35572c97efb5a8239c74241189a9bbf6ed7040ab6ee65814760293ebfc7d01fe7a2cf977cb0ebfe0a529defaef9cd563
|
7
|
+
data.tar.gz: e72884ae0d2b43d12e838c8e1bd77f6b9f019c69d7a257d7272ac699cdb055333794fc1b10909f16301d96b60565525f96e207e54a63b6d2270c72b26bdf1a52
|
data/README.md
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
# Tilda::Simple::Api
|
2
|
+
[](https://badge.fury.io/rb/tilda-simple-api)
|
2
3
|
[](https://travis-ci.org/gururuby/tilda-simple-api)
|
3
4
|
[](https://codeclimate.com/github/gururuby/tilda-simple-api/maintainability)
|
4
5
|
[](https://codeclimate.com/github/gururuby/tilda-simple-api/test_coverage)
|
@@ -31,6 +32,7 @@ Configuration api:
|
|
31
32
|
config.secret_key = "your-secret-key"
|
32
33
|
# config.api_version = "v1" # by default'
|
33
34
|
# config.api_host = "http://api.tildacdn.info" # by default'
|
35
|
+
# config.raise_api_errors = false # by_default
|
34
36
|
end
|
35
37
|
```
|
36
38
|
|
@@ -55,6 +57,17 @@ API requests example
|
|
55
57
|
| **page info for export(only body)** | `tilda_api.page_export(page_id)` | http://help.tilda.ws/api#getpageexport |
|
56
58
|
| **full page info for export** | `tilda_api.page_full_export(page_id)` | http://help.tilda.ws/api#getpagefullexport |
|
57
59
|
|
60
|
+
### API Errors
|
61
|
+
When switch `config.raise_api_errors` to `true`. API raise errors. Here is available API Errors:
|
62
|
+
|
63
|
+
| API Error | Error case |
|
64
|
+
| --------------------------------------------------|-------------------------------------------------|
|
65
|
+
| **Tilda::Simple::Api::Errors::InvalidCredentials**| invalid public_key or secret_key passed |
|
66
|
+
| **Tilda::Simple::Api::Errors::ProjectNotFound** | tilda api not found project by passed project_id|
|
67
|
+
| **Tilda::Simple::Api::Errors::PageNotFound** | tilda api not found page by passed page_id |
|
68
|
+
| **Tilda::Simple::Api::Errors::Error** | in all other cases |
|
69
|
+
|
70
|
+
|
58
71
|
## Contributing
|
59
72
|
|
60
73
|
Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/tilda-simple-api. 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.
|
data/lib/tilda/simple/api.rb
CHANGED
@@ -2,11 +2,12 @@ module Tilda
|
|
2
2
|
module Simple
|
3
3
|
module Api
|
4
4
|
class Config
|
5
|
-
attr_accessor :api_host, :api_version, :public_key, :secret_key
|
5
|
+
attr_accessor :api_host, :api_version, :public_key, :secret_key, :raise_api_errors
|
6
6
|
|
7
7
|
def initialize
|
8
8
|
@api_version = 'v1'
|
9
9
|
@api_host = 'http://api.tildacdn.info'
|
10
|
+
@raise_api_errors = false
|
10
11
|
end
|
11
12
|
end
|
12
13
|
end
|
@@ -3,15 +3,9 @@ module Tilda
|
|
3
3
|
module Api
|
4
4
|
module Errors
|
5
5
|
class Error < StandardError; end
|
6
|
-
|
7
|
-
class
|
8
|
-
|
9
|
-
|
10
|
-
def initialize(response)
|
11
|
-
@message = response.message
|
12
|
-
@status_code = response.code
|
13
|
-
end
|
14
|
-
end
|
6
|
+
class InvalidCredentials < Error; end
|
7
|
+
class ProjectNotFound < Error; end
|
8
|
+
class PageNotFound < Error; end
|
15
9
|
end
|
16
10
|
end
|
17
11
|
end
|
@@ -0,0 +1,36 @@
|
|
1
|
+
module Tilda
|
2
|
+
module Simple
|
3
|
+
module Api
|
4
|
+
module ErrorsHandler
|
5
|
+
def get(path, params = {})
|
6
|
+
handle_errors { super(path, params) }
|
7
|
+
end
|
8
|
+
|
9
|
+
private
|
10
|
+
|
11
|
+
def handle_errors(&block)
|
12
|
+
response = block.call
|
13
|
+
check_response(response) if Api.config.raise_api_errors
|
14
|
+
response
|
15
|
+
end
|
16
|
+
|
17
|
+
def check_response(response)
|
18
|
+
raise api_error_class(response), response['message'] if response['status'] == 'ERROR'
|
19
|
+
end
|
20
|
+
|
21
|
+
def api_error_class(response)
|
22
|
+
case response['message']
|
23
|
+
when /Wrong Secret Key length|Wrong Public Key length/
|
24
|
+
Errors::InvalidCredentials
|
25
|
+
when /Can't find project with this 'projectid' parameter/
|
26
|
+
Errors::ProjectNotFound
|
27
|
+
when /Can't find page with this 'pageid' parameter/
|
28
|
+
Errors::PageNotFound
|
29
|
+
else
|
30
|
+
Errors::Error
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
@@ -2,52 +2,49 @@ module Tilda
|
|
2
2
|
module Simple
|
3
3
|
module Api
|
4
4
|
class Request
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
def page_full_export(page_id)
|
49
|
-
self.class.get('/getpagefullexport', query: { pageid: page_id })
|
50
|
-
end
|
5
|
+
include HTTParty
|
6
|
+
extend ErrorsHandler
|
7
|
+
|
8
|
+
def initialize(public_key: nil, secret_key: nil)
|
9
|
+
config = Api.config
|
10
|
+
|
11
|
+
public_key ||= config.public_key
|
12
|
+
secret_key ||= config.secret_key
|
13
|
+
|
14
|
+
self.class.base_uri "#{config.api_host}/#{config.api_version}"
|
15
|
+
self.class.default_params publickey: public_key, secretkey: secret_key
|
16
|
+
end
|
17
|
+
|
18
|
+
def projects_list
|
19
|
+
self.class.get('/getprojectslist')
|
20
|
+
end
|
21
|
+
|
22
|
+
def project(project_id)
|
23
|
+
self.class.get('/getproject', query: { projectid: project_id })
|
24
|
+
end
|
25
|
+
|
26
|
+
def project_export(project_id)
|
27
|
+
self.class.get('/getprojectexport', query: { projectid: project_id })
|
28
|
+
end
|
29
|
+
|
30
|
+
def pages_list(project_id)
|
31
|
+
self.class.get('/getpageslist', query: { projectid: project_id })
|
32
|
+
end
|
33
|
+
|
34
|
+
def page(page_id)
|
35
|
+
self.class.get('/getpage', query: { pageid: page_id })
|
36
|
+
end
|
37
|
+
|
38
|
+
def page_full(page_id)
|
39
|
+
self.class.get('/getpagefull', query: { pageid: page_id })
|
40
|
+
end
|
41
|
+
|
42
|
+
def page_export(page_id)
|
43
|
+
self.class.get('/getpageexport', query: { pageid: page_id })
|
44
|
+
end
|
45
|
+
|
46
|
+
def page_full_export(page_id)
|
47
|
+
self.class.get('/getpagefullexport', query: { pageid: page_id })
|
51
48
|
end
|
52
49
|
end
|
53
50
|
end
|
data/tilda-simple-api.gemspec
CHANGED
@@ -28,6 +28,7 @@ Gem::Specification.new do |spec|
|
|
28
28
|
spec.bindir = "exe"
|
29
29
|
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
30
30
|
spec.require_paths = ["lib"]
|
31
|
+
spec.required_ruby_version = '>= 1.9.3'
|
31
32
|
|
32
33
|
spec.add_development_dependency "bundler", "~> 1.16"
|
33
34
|
spec.add_development_dependency "rake", "~> 10.0"
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: tilda-simple-api
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- V. Miroshnichenko
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-12-
|
11
|
+
date: 2018-12-17 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -114,6 +114,7 @@ files:
|
|
114
114
|
- lib/tilda/simple/api.rb
|
115
115
|
- lib/tilda/simple/api/config.rb
|
116
116
|
- lib/tilda/simple/api/errors.rb
|
117
|
+
- lib/tilda/simple/api/errors_handler.rb
|
117
118
|
- lib/tilda/simple/api/request.rb
|
118
119
|
- lib/tilda/simple/api/version.rb
|
119
120
|
- tilda-simple-api.gemspec
|
@@ -130,7 +131,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
130
131
|
requirements:
|
131
132
|
- - ">="
|
132
133
|
- !ruby/object:Gem::Version
|
133
|
-
version:
|
134
|
+
version: 1.9.3
|
134
135
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
135
136
|
requirements:
|
136
137
|
- - ">="
|