tilda-api 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: ecd0c17ade100f9c8f4be1120a73f95963bf1ee4
4
+ data.tar.gz: 04ce1dea2bc41603fb41f85be185ab51d5236b28
5
+ SHA512:
6
+ metadata.gz: e703547278e2e0449b5c34897983689cf3ea9d6ac07f7b0d0ff4872f5f5a9d05b6b65b2e3c71559f6ab0c3b40d935fed27ba9d2243d773dbe4da280f31b06ee8
7
+ data.tar.gz: ca732a2c72f1666282e7756adf3ff9202686996693af17e31f764418bb6b1b7e5ec99fc86379406567ee9b80af949b7fc739e3a57ee6baff538bb4728c6d3719
@@ -0,0 +1,21 @@
1
+ require 'httparty'
2
+ require 'tilda/api/configuration'
3
+ require "tilda/api/errors"
4
+ require "tilda/api/request"
5
+ require "tilda/api/version"
6
+
7
+ module Tilda
8
+ module Api
9
+ class << self
10
+ attr_writer :configuration
11
+ end
12
+
13
+ def self.configuration
14
+ @configuration ||= Configuration.new
15
+ end
16
+
17
+ def self.configure
18
+ yield(configuration)
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,13 @@
1
+ module Tilda
2
+ module Api
3
+ class Configuration
4
+ attr_accessor :api_version
5
+ attr_accessor :public_key
6
+ attr_accessor :secret_key
7
+
8
+ def initialize
9
+ @api_version = "v1"
10
+ end
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,14 @@
1
+ module Tilda
2
+ module Api
3
+ module Errors
4
+ class Error < StandardError; end
5
+ class ResponseError < Error
6
+ attr_reader :status_code
7
+ def initialize(response)
8
+ @message = response.message
9
+ @status_code = response.code
10
+ end
11
+ end
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,58 @@
1
+ module Tilda
2
+ module Api
3
+ class Request
4
+
5
+ class << self
6
+ def new(public_key:nil, secret_key:nil)
7
+ Class.new(AbstractRequest){|klass|
8
+ public_key ||= Api.configuration.public_key
9
+ secret_key ||= Api.configuration.secret_key
10
+ api_version = Api.configuration.api_version
11
+ klass.base_uri "http://api.tildacdn.info/#{api_version}"
12
+ klass.default_params publickey: public_key, secretkey: secret_key
13
+ }.new
14
+ end
15
+ end
16
+
17
+ class AbstractRequest
18
+ include HTTParty
19
+
20
+ def get_projects_list
21
+ self.class.get('/getprojectslist')
22
+ end
23
+
24
+ def get_project(project_id)
25
+ self.class.get('/getproject', query: {projectid: project_id})
26
+ end
27
+
28
+ def get_project_export(project_id)
29
+ self.class.get('/getprojectexport', query: {projectid: project_id})
30
+ end
31
+
32
+ def get_pages_list(project_id)
33
+ response = self.class.get('/getpageslist', query: {projectid: project_id})
34
+ if response["result"].nil?
35
+ response["status"] = "ERROR"
36
+ end
37
+ response
38
+ end
39
+
40
+ def get_page(page_id)
41
+ self.class.get('/getpage', query: {pageid: page_id})
42
+ end
43
+
44
+ def get_page_full(page_id)
45
+ self.class.get('/getpagefull', query: {pageid: page_id})
46
+ end
47
+
48
+ def get_page_export(page_id)
49
+ self.class.get('/getpageexport', query: {pageid: page_id})
50
+ end
51
+
52
+ def get_page_full_export(page_id)
53
+ self.class.get('/getpagefullexport', query: {pageid: page_id})
54
+ end
55
+ end
56
+ end
57
+ end
58
+ end
@@ -0,0 +1,5 @@
1
+ module Tilda
2
+ module Api
3
+ VERSION = "0.0.1"
4
+ end
5
+ end
@@ -0,0 +1,130 @@
1
+ describe Tilda::Api::Request do
2
+ let(:public_key){ENV.fetch("TILDA_PUBLIC_KEY")}
3
+ let(:secret_key){ENV.fetch("TILDA_SECRET_KEY")}
4
+ let(:project_id){ENV.fetch("TILDA_PROJECT_ID")}
5
+ let(:page_id){ENV.fetch("TILDA_PAGE_ID")}
6
+
7
+ subject{described_class.new(public_key: public_key, secret_key: secret_key)}
8
+
9
+ describe "#get_projects_list" do
10
+ it "return list of projects" do
11
+ VCR.use_cassette("succsesful_projects_list", record: :once) do
12
+ response = subject.get_projects_list
13
+ expect(response["status"]).to eq("FOUND")
14
+ end
15
+ end
16
+ end
17
+
18
+ describe "#get_project" do
19
+ it "return project" do
20
+ VCR.use_cassette("succsesful_get_project", record: :once) do
21
+ response = subject.get_project(project_id)
22
+ expect(response["status"]).to eq("FOUND")
23
+ end
24
+ end
25
+
26
+ it "not found project" do
27
+ VCR.use_cassette("notfound_get_project", record: :once) do
28
+ response = subject.get_project(-1)
29
+ expect(response["status"]).to eq("ERROR")
30
+ end
31
+ end
32
+ end
33
+
34
+ describe "#get_project_export" do
35
+ it "successful request" do
36
+ VCR.use_cassette("successfull_get_project_export", record: :once) do
37
+ response = subject.get_project_export(13862)
38
+ expect(response["status"]).to eq("FOUND")
39
+ end
40
+ end
41
+
42
+ it "not found project for export" do
43
+ VCR.use_cassette("notfound_get_project_export", record: :once) do
44
+ response = subject.get_project_export(-1)
45
+ expect(response["status"]).to eq("ERROR")
46
+ end
47
+ end
48
+ end
49
+
50
+ describe "#get_pages_list" do
51
+ it "successfull request" do
52
+ VCR.use_cassette("successfull_get_pages_list", record: :once) do
53
+ response = subject.get_pages_list(project_id)
54
+ expect(response["status"]).to eq("FOUND")
55
+ end
56
+ end
57
+
58
+ it "invalid response" do
59
+ VCR.use_cassette("notfound_get_pages_list", record: :once) do
60
+ response = subject.get_pages_list(1)
61
+ expect(response["status"]).to eq("ERROR")
62
+ end
63
+ end
64
+ end
65
+
66
+ describe "#get_page" do
67
+ it "successfull request" do
68
+ VCR.use_cassette("successfull_get_page", record: :once) do
69
+ response = subject.get_page(page_id)
70
+ expect(response["status"]).to eq("FOUND")
71
+ end
72
+ end
73
+
74
+ it "invalid response" do
75
+ VCR.use_cassette("invalid_get_page", record: :once) do
76
+ response = subject.get_page(1)
77
+ expect(response["status"]).to eq("ERROR")
78
+ end
79
+ end
80
+ end
81
+
82
+ describe "#get_page_full" do
83
+ it "successfull request" do
84
+ VCR.use_cassette("successfull_get_page_full", record: :once) do
85
+ response = subject.get_page_full(page_id)
86
+ expect(response["status"]).to eq("FOUND")
87
+ end
88
+ end
89
+
90
+ it "invalid response" do
91
+ VCR.use_cassette("invalid_get_page_full", record: :once) do
92
+ response = subject.get_page_full(-1)
93
+ expect(response["status"]).to eq("ERROR")
94
+ end
95
+ end
96
+ end
97
+
98
+ describe "#get_page_export" do
99
+ it "successfull response" do
100
+ VCR.use_cassette("successfull_get_page_export", record: :once) do
101
+ response = subject.get_page_export(page_id)
102
+ expect(response["status"]).to eq("FOUND")
103
+ end
104
+ end
105
+
106
+ it "invalid response" do
107
+ VCR.use_cassette("invalid_get_page_export", record: :once) do
108
+ response = subject.get_page_export(-1)
109
+ expect(response["status"]).to eq("ERROR")
110
+ end
111
+ end
112
+ end
113
+
114
+ describe "#get_page_full_export" do
115
+ it "successfull response" do
116
+ VCR.use_cassette("successfull_get_page_full_export", record: :once) do
117
+ response = subject.get_page_full_export(page_id)
118
+ expect(response["status"]).to eq("FOUND")
119
+ end
120
+ end
121
+
122
+ it "invalid response" do
123
+ VCR.use_cassette("invalid_get_page_full_export", record: :once) do
124
+ response = subject.get_page_full_export(-1)
125
+ expect(response["status"]).to eq("ERROR")
126
+ end
127
+ end
128
+ end
129
+
130
+ end
@@ -0,0 +1,100 @@
1
+ require "codeclimate-test-reporter"
2
+ CodeClimate::TestReporter.start
3
+ # This file was generated by the `rspec --init` command. Conventionally, all
4
+ # specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
5
+ # The generated `.rspec` file contains `--require spec_helper` which will cause
6
+ # this file to always be loaded, without a need to explicitly require it in any
7
+ # files.
8
+ #
9
+ # Given that it is always loaded, you are encouraged to keep this file as
10
+ # light-weight as possible. Requiring heavyweight dependencies from this file
11
+ # will add to the boot time of your test suite on EVERY test run, even for an
12
+ # individual file that may not need all of that loaded. Instead, consider making
13
+ # a separate helper file that requires the additional dependencies and performs
14
+ # the additional setup, and require it from the spec files that actually need
15
+ # it.
16
+ #
17
+ # The `.rspec` file also contains a few flags that are not defaults but that
18
+ # users commonly want.
19
+ #
20
+ # See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
21
+
22
+ require 'pry'
23
+ require File.expand_path('../../lib/tilda/api', __FILE__)
24
+
25
+ Dir[File.dirname(__FILE__) + "/supports/**/*.rb"].each {|f| require f }
26
+
27
+
28
+ RSpec.configure do |config|
29
+ # rspec-expectations config goes here. You can use an alternate
30
+ # assertion/expectation library such as wrong or the stdlib/minitest
31
+ # assertions if you prefer.
32
+ config.expect_with :rspec do |expectations|
33
+ # This option will default to `true` in RSpec 4. It makes the `description`
34
+ # and `failure_message` of custom matchers include text for helper methods
35
+ # defined using `chain`, e.g.:
36
+ # be_bigger_than(2).and_smaller_than(4).description
37
+ # # => "be bigger than 2 and smaller than 4"
38
+ # ...rather than:
39
+ # # => "be bigger than 2"
40
+ expectations.include_chain_clauses_in_custom_matcher_descriptions = true
41
+ end
42
+
43
+ # rspec-mocks config goes here. You can use an alternate test double
44
+ # library (such as bogus or mocha) by changing the `mock_with` option here.
45
+ config.mock_with :rspec do |mocks|
46
+ # Prevents you from mocking or stubbing a method that does not exist on
47
+ # a real object. This is generally recommended, and will default to
48
+ # `true` in RSpec 4.
49
+ mocks.verify_partial_doubles = true
50
+ end
51
+
52
+ # The settings below are suggested to provide a good initial experience
53
+ # with RSpec, but feel free to customize to your heart's content.
54
+ =begin
55
+ # These two settings work together to allow you to limit a spec run
56
+ # to individual examples or groups you care about by tagging them with
57
+ # `:focus` metadata. When nothing is tagged with `:focus`, all examples
58
+ # get run.
59
+ config.filter_run :focus
60
+ config.run_all_when_everything_filtered = true
61
+
62
+ # Limits the available syntax to the non-monkey patched syntax that is
63
+ # recommended. For more details, see:
64
+ # - http://myronmars.to/n/dev-blog/2012/06/rspecs-new-expectation-syntax
65
+ # - http://teaisaweso.me/blog/2013/05/27/rspecs-new-message-expectation-syntax/
66
+ # - http://myronmars.to/n/dev-blog/2014/05/notable-changes-in-rspec-3#new__config_option_to_disable_rspeccore_monkey_patching
67
+ config.disable_monkey_patching!
68
+
69
+ # This setting enables warnings. It's recommended, but in some cases may
70
+ # be too noisy due to issues in dependencies.
71
+ config.warnings = true
72
+
73
+ # Many RSpec users commonly either run the entire suite or an individual
74
+ # file, and it's useful to allow more verbose output when running an
75
+ # individual spec file.
76
+ if config.files_to_run.one?
77
+ # Use the documentation formatter for detailed output,
78
+ # unless a formatter has already been configured
79
+ # (e.g. via a command-line flag).
80
+ config.default_formatter = 'doc'
81
+ end
82
+
83
+ # Print the 10 slowest examples and example groups at the
84
+ # end of the spec run, to help surface which specs are running
85
+ # particularly slow.
86
+ config.profile_examples = 10
87
+
88
+ # Run specs in random order to surface order dependencies. If you find an
89
+ # order dependency and want to debug it, you can fix the order by providing
90
+ # the seed, which is printed after each run.
91
+ # --seed 1234
92
+ config.order = :random
93
+
94
+ # Seed global randomization in this process using the `--seed` CLI option.
95
+ # Setting this allows you to use `--seed` to deterministically reproduce
96
+ # test failures related to randomization by passing the same `--seed` value
97
+ # as the one that triggered the failure.
98
+ Kernel.srand config.seed
99
+ =end
100
+ end
@@ -0,0 +1,11 @@
1
+ require 'vcr'
2
+ VCR.configure do |c|
3
+ c.cassette_library_dir = 'fixtures/vcr_cassettes'
4
+ c.default_cassette_options = { :record => :once }
5
+ c.ignore_hosts 'codeclimate.com'
6
+ c.hook_into :webmock
7
+ end
8
+
9
+ RSpec.configure do |c|
10
+ c.extend VCR::RSpec::Macros
11
+ end
metadata ADDED
@@ -0,0 +1,195 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: tilda-api
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Eugene Stepanov
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-08-23 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.7'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.7'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: vcr
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: webmock
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: pry
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: pry-remote
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ">="
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
111
+ - !ruby/object:Gem::Dependency
112
+ name: pry-stack_explorer
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - ">="
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - ">="
123
+ - !ruby/object:Gem::Version
124
+ version: '0'
125
+ - !ruby/object:Gem::Dependency
126
+ name: pry-debugger
127
+ requirement: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - ">="
130
+ - !ruby/object:Gem::Version
131
+ version: '0'
132
+ type: :development
133
+ prerelease: false
134
+ version_requirements: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - ">="
137
+ - !ruby/object:Gem::Version
138
+ version: '0'
139
+ - !ruby/object:Gem::Dependency
140
+ name: httparty
141
+ requirement: !ruby/object:Gem::Requirement
142
+ requirements:
143
+ - - ">="
144
+ - !ruby/object:Gem::Version
145
+ version: '0'
146
+ type: :runtime
147
+ prerelease: false
148
+ version_requirements: !ruby/object:Gem::Requirement
149
+ requirements:
150
+ - - ">="
151
+ - !ruby/object:Gem::Version
152
+ version: '0'
153
+ description: Tilda API
154
+ email:
155
+ - antynitr@gmail.com
156
+ executables: []
157
+ extensions: []
158
+ extra_rdoc_files: []
159
+ files:
160
+ - lib/tilda/api.rb
161
+ - lib/tilda/api/configuration.rb
162
+ - lib/tilda/api/errors.rb
163
+ - lib/tilda/api/request.rb
164
+ - lib/tilda/api/version.rb
165
+ - spec/lib/tilda/api/request_spec.rb
166
+ - spec/spec_helper.rb
167
+ - spec/supports/vcr.rb
168
+ homepage: ''
169
+ licenses:
170
+ - MIT
171
+ metadata: {}
172
+ post_install_message:
173
+ rdoc_options: []
174
+ require_paths:
175
+ - lib
176
+ required_ruby_version: !ruby/object:Gem::Requirement
177
+ requirements:
178
+ - - ">="
179
+ - !ruby/object:Gem::Version
180
+ version: '0'
181
+ required_rubygems_version: !ruby/object:Gem::Requirement
182
+ requirements:
183
+ - - ">="
184
+ - !ruby/object:Gem::Version
185
+ version: '0'
186
+ requirements: []
187
+ rubyforge_project:
188
+ rubygems_version: 2.2.2
189
+ signing_key:
190
+ specification_version: 4
191
+ summary: Tilda API
192
+ test_files:
193
+ - spec/lib/tilda/api/request_spec.rb
194
+ - spec/spec_helper.rb
195
+ - spec/supports/vcr.rb