tilda 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: a605017e1c487947b1d5f8ee072fa5ff92050babc90d76836b108b5f9f806dc4
4
+ data.tar.gz: 5554f700a7d971cc23e31f814c727141a780b9043b136c3c6b6144608ad95dcd
5
+ SHA512:
6
+ metadata.gz: eb0dc4b7318c8adace208db0f4adcb1fecc8a108aed801af5571572fe56cc45367a83e86fe7ab7503625e7d1e488b7e270e1ad1d7b4f0b2b5940810b09c3222d
7
+ data.tar.gz: c2ab27794a25d6cf42f863c89db889e001cf901126bba7d34c37e6d14dbb7c672240619f6de38218495d25a2c5334ebde4272dd8665b256824d25a955a6335cb
@@ -0,0 +1,23 @@
1
+ .idea
2
+ .git
3
+ .config
4
+ Gemfile.lock
5
+ /.bundle/
6
+ /.yardoc
7
+ /_yardoc/
8
+ /coverage/
9
+ /doc/
10
+ /pkg/
11
+ /spec/reports/
12
+ /tmp/
13
+ /vendor/
14
+ # rspec failure tracking
15
+ .rspec_status
16
+
17
+ # dockerized development environment
18
+ Dockerfile
19
+ docker-compose.yml
20
+ Makefile
21
+
22
+ # misc test files
23
+ test.rb
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
@@ -0,0 +1,7 @@
1
+ ---
2
+ sudo: false
3
+ language: ruby
4
+ cache: bundler
5
+ rvm:
6
+ - 2.5.1
7
+ before_install: gem install bundler -v 1.16.4
data/Gemfile ADDED
@@ -0,0 +1,6 @@
1
+ source "https://rubygems.org"
2
+
3
+ git_source(:github) {|repo_name| "https://github.com/#{repo_name}" }
4
+
5
+ # Specify your gem's dependencies in tilda.gemspec
6
+ gemspec
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2018 TODO: Write your name
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.
@@ -0,0 +1,41 @@
1
+ # Tilda
2
+
3
+ English version will be later (or not)
4
+
5
+ Этот гем позволяет работать с API сайта Tilda.cc (tilda.ws)
6
+ Пока готова только часть, которая позволяет делать API запросы.
7
+
8
+ Далее планируются отдельные слои, для работы со страницей, кэширования страниц локально и рендеринга страниц во view.
9
+
10
+ ## Installation
11
+
12
+ Add this line to your application's Gemfile:
13
+
14
+ ```ruby
15
+ gem 'tilda'
16
+ ```
17
+
18
+ And then execute:
19
+
20
+ $ bundle
21
+
22
+ Or install it yourself as:
23
+
24
+ $ gem install tilda
25
+
26
+ ## Usage
27
+
28
+ Смотри папку examples
29
+
30
+ ## Development
31
+
32
+ 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.
33
+
34
+ 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).
35
+
36
+ ## Contributing
37
+
38
+
39
+ ## License
40
+
41
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
@@ -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
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "tilda"
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__)
@@ -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,10 @@
1
+ require 'tilda/version'
2
+ require 'tilda/config'
3
+ require 'tilda/page'
4
+ require 'tilda/client'
5
+ require 'tilda/downloader'
6
+ require 'tilda/cache'
7
+
8
+ module Tilda
9
+
10
+ end
@@ -0,0 +1,44 @@
1
+ module Tilda
2
+ class Cache
3
+ def initialize(cache_path = nil)
4
+ @cache_path = cache_path || Config.config.cache_path
5
+ if @cache_path.nil?
6
+ @cache_path = defined?(Rails) ? "#{Rails.public_path}/tilda/" : "/tmp/tilda/"
7
+ end
8
+ end
9
+
10
+ def get_cached_page(id)
11
+ @cache_path
12
+ end
13
+
14
+ def cache_page(id)
15
+
16
+ end
17
+
18
+ def get_page_by_id
19
+
20
+ end
21
+
22
+ #private
23
+
24
+ def clear_page(page)
25
+ FileUtils.rmdir(get_page_fullpath(page), noop: true, verbose: true) #TODO: really do nothing
26
+ end
27
+
28
+ def get_page_dirname(page)
29
+ "#{page.get_html_filename}__#{page.get_published_timestamp}"
30
+ end
31
+
32
+ def get_page_fullpath(page)
33
+ "#{@cache_path}/#{get_page_dirname(page)}"
34
+ end
35
+
36
+ private
37
+
38
+ def mk_path(path)
39
+ FileUtils.mkdir_p(path) unless File.directory?(path)
40
+ end
41
+
42
+
43
+ end
44
+ end
@@ -0,0 +1,57 @@
1
+ require 'httparty'
2
+
3
+ module Tilda
4
+ class Client
5
+ include HTTParty
6
+ base_uri 'http://api.tildacdn.info/v1'
7
+
8
+ parser(
9
+ proc do |body, format|
10
+ #raise 'Error while parsing response' if format != :json #TODO: replace with Error class
11
+ JSON.parse(body, { symbolize_names: true })
12
+ end
13
+ )
14
+
15
+ def get_projects_list
16
+ self.class.get '/getprojectslist', query_params
17
+ end
18
+
19
+ def get_project(id)
20
+ self.class.get '/getproject', query_params(projectid: id)
21
+ end
22
+
23
+ def get_project_export(id)
24
+ self.class.get '/getprojectexport', query_params(projectid: id)
25
+ end
26
+
27
+ def get_pages_list(id)
28
+ self.class.get '/getpageslist', query_params(projectid: id)
29
+ end
30
+
31
+ def get_page(id)
32
+ self.class.get '/getpage', query_params(pageid: id)
33
+ end
34
+
35
+ def get_page_full(id)
36
+ self.class.get '/getpagefull', query_params(pageid: id)
37
+ end
38
+
39
+ def get_page_export(id)
40
+ self.class.get '/getpageexport', query_params(pageid: id)
41
+ end
42
+
43
+ def get_page_full_export(id)
44
+ self.class.get '/getpagefullexport', query_params(pageid: id)
45
+ end
46
+
47
+ private
48
+
49
+ def query_params(params = {})
50
+ { query: params.merge(auth_keys) }
51
+ end
52
+
53
+ def auth_keys
54
+ { publickey: Config.config.public_key, secretkey: Config.config.private_key }
55
+ end
56
+ end
57
+ end
@@ -0,0 +1,10 @@
1
+ require 'dry-configurable'
2
+
3
+ module Tilda
4
+ class Config
5
+ extend Dry::Configurable
6
+ setting :public_key
7
+ setting :private_key
8
+ setting :cache_path
9
+ end
10
+ end
@@ -0,0 +1,19 @@
1
+ require 'httparty'
2
+ require 'fileutils'
3
+
4
+
5
+ module Tilda
6
+ class Downloader
7
+ def initialize(save_path)
8
+ @save_path = save_path
9
+ end
10
+
11
+ def save_project(id)
12
+
13
+ end
14
+
15
+ def save_page(id)
16
+
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,106 @@
1
+ module Tilda
2
+ class Page
3
+ def initialize(id, only_body: nil)
4
+ raise 'Page id must be set when creating class' if id.nil?
5
+ @page_id = id
6
+ @only_body = only_body
7
+ @current_page = nil
8
+ end
9
+
10
+ def get_current_page
11
+ @current_page ||= fetch_page(@only_body).dig(:result)
12
+ end
13
+
14
+ def fetch_page(only_body)
15
+ if only_body.nil?
16
+ page = Client.new.get_page_full_export(@page_id)
17
+ else
18
+ page = Client.new.get_page_export(@page_id)
19
+ end
20
+ raise "Page not found" if page[:status] != 'FOUND' #TODO: replace with Error class
21
+ return page
22
+ end
23
+
24
+ def get_html_code
25
+ get_current_page.dig(:html)
26
+ end
27
+
28
+ def get_html_filename
29
+ get_current_page.dig(:filename)
30
+ end
31
+
32
+ def get_html_meta_tags(files_url_path = nil)
33
+ tags_list = ''
34
+ get_css_files.each {|filename| tags_list << "<link rel=\"stylesheet\" href=\"#{files_url_path}#{filename}\" type=\"text/css\" media=\"all\"/>\n" }
35
+ get_js_files.each {|filename| tags_list << "<script src=\"#{files_url_path}#{filename}\"></script>\n" }
36
+ return tags_list
37
+ end
38
+
39
+ def get_published_timestamp
40
+ get_current_page.dig(:published)
41
+ end
42
+
43
+ def get_css_struct
44
+ get_current_page.dig(:css)
45
+ end
46
+
47
+ def get_js_struct
48
+ get_current_page.dig(:js)
49
+ end
50
+
51
+ def get_img_struct
52
+ get_current_page.dig(:images)
53
+ end
54
+
55
+ def get_img_files
56
+ get_img_struct.map { |struct| struct[:to] }
57
+ end
58
+
59
+ def get_css_files
60
+ get_css_struct.map { |struct| struct[:to] }
61
+ end
62
+
63
+ def get_js_files
64
+ get_js_struct.map { |struct| struct[:to] }
65
+ end
66
+
67
+ def save_js(path)
68
+ download_files(get_js_struct, path) unless get_js_struct.nil?
69
+ end
70
+
71
+ def save_css(path)
72
+ download_files(get_css_struct, path) unless get_css_struct.nil?
73
+ end
74
+
75
+ def save_img(path)
76
+ download_files(get_img_struct, path) unless get_img_struct.nil?
77
+ end
78
+
79
+ def save_html(path)
80
+ full_name = "#{path}/#{get_html_filename}"
81
+ File.open(full_name, "w") { |file| file.write(get_html_code) }
82
+ end
83
+
84
+ def save(path)
85
+ save_js(path)
86
+ save_css(path)
87
+ save_img(path)
88
+ save_html(path)
89
+ end
90
+
91
+ private
92
+
93
+ def download_file(url, full_name)
94
+ File.open(full_name, "w") do |file|
95
+ HTTParty.get(url, stream_body: true) { |fragment| file.write(fragment) }
96
+ end
97
+ end
98
+
99
+ def download_files(url_name_list, path)
100
+ return if url_name_list.empty?
101
+ url_name_list.each do |file_info|
102
+ download_file(file_info[:from], "#{path}/#{file_info[:to]}")
103
+ end
104
+ end
105
+ end
106
+ end
@@ -0,0 +1,3 @@
1
+ module Tilda
2
+ VERSION = "0.1.0"
3
+ end
@@ -0,0 +1,35 @@
1
+
2
+ lib = File.expand_path("../lib", __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require "tilda/version"
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "tilda"
8
+ spec.version = Tilda::VERSION
9
+ spec.authors = ["Alexander Pashchenko"]
10
+ spec.email = ["point212@gmail.com"]
11
+
12
+ spec.summary = %q{This gem provide some Ruby bindigs for tilda.cc API}
13
+ spec.homepage = "https://github.com/smmarty/tilda_friflex"
14
+ spec.license = "MIT"
15
+
16
+
17
+ # Specify which files should be added to the gem when it is released.
18
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
19
+ spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
20
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
21
+ end
22
+ spec.bindir = "exe"
23
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
24
+ spec.require_paths = ["lib"]
25
+
26
+ spec.add_development_dependency "bundler", "~> 1.16"
27
+ spec.add_development_dependency "rake", "~> 10.0"
28
+ spec.add_development_dependency "rspec", "~> 3.0"
29
+ spec.add_development_dependency 'vcr'
30
+ spec.add_development_dependency 'webmock'
31
+
32
+ spec.add_runtime_dependency 'httparty'
33
+ spec.add_runtime_dependency 'dry-configurable'
34
+ spec.add_runtime_dependency 'fileutils'
35
+ end
metadata ADDED
@@ -0,0 +1,173 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: tilda
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Alexander Pashchenko
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2018-11-13 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.16'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.16'
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: '3.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '3.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: httparty
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :runtime
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: dry-configurable
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ type: :runtime
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: fileutils
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - ">="
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ type: :runtime
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - ">="
123
+ - !ruby/object:Gem::Version
124
+ version: '0'
125
+ description:
126
+ email:
127
+ - point212@gmail.com
128
+ executables: []
129
+ extensions: []
130
+ extra_rdoc_files: []
131
+ files:
132
+ - ".gitignore"
133
+ - ".rspec"
134
+ - ".travis.yml"
135
+ - Gemfile
136
+ - LICENSE.txt
137
+ - README.md
138
+ - Rakefile
139
+ - bin/console
140
+ - bin/setup
141
+ - lib/tilda.rb
142
+ - lib/tilda/cache.rb
143
+ - lib/tilda/client.rb
144
+ - lib/tilda/config.rb
145
+ - lib/tilda/downloader.rb
146
+ - lib/tilda/page.rb
147
+ - lib/tilda/version.rb
148
+ - tilda.gemspec
149
+ homepage: https://github.com/smmarty/tilda_friflex
150
+ licenses:
151
+ - MIT
152
+ metadata: {}
153
+ post_install_message:
154
+ rdoc_options: []
155
+ require_paths:
156
+ - lib
157
+ required_ruby_version: !ruby/object:Gem::Requirement
158
+ requirements:
159
+ - - ">="
160
+ - !ruby/object:Gem::Version
161
+ version: '0'
162
+ required_rubygems_version: !ruby/object:Gem::Requirement
163
+ requirements:
164
+ - - ">="
165
+ - !ruby/object:Gem::Version
166
+ version: '0'
167
+ requirements: []
168
+ rubyforge_project:
169
+ rubygems_version: 2.7.7
170
+ signing_key:
171
+ specification_version: 4
172
+ summary: This gem provide some Ruby bindigs for tilda.cc API
173
+ test_files: []