jahuty-snippet 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +45 -0
- data/.rspec +3 -0
- data/Gemfile +4 -0
- data/LICENSE +21 -0
- data/README.md +47 -0
- data/Rakefile +6 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/jahuty-snippets.gemspec +29 -0
- data/lib/jahuty/snippet.rb +27 -0
- data/lib/jahuty/snippet/data/problem.rb +23 -0
- data/lib/jahuty/snippet/data/snippet.rb +25 -0
- data/lib/jahuty/snippet/exception/not_ok.rb +17 -0
- data/lib/jahuty/snippet/service/connect.rb +25 -0
- data/lib/jahuty/snippet/service/get.rb +30 -0
- data/lib/jahuty/snippet/version.rb +5 -0
- metadata +116 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 57ae6dd9efa5f965a125e881791d95839e93e686d35f1752d14184dbff402a4e
|
4
|
+
data.tar.gz: 2a595ffc718556e197b8c124457910f4059ed3af2cac8c3a929b3758c8147fe2
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 8d903c8a9109bd292b59dd89a4372cd1fdcfe9a4861221d58f901ee3cd6a3942b62cd22a3248e88438f9acdefbeb57cac60327c042626794bab1e441ec3f581e
|
7
|
+
data.tar.gz: 0e5aab16fb37647743a1aa89e2e3ebbee6e25f9791bbb7cd086c096e6b5ac1da90890b8b9d9d4ca4b34379444cc4f719fd35123d6f2f7a1dda919be26e74978b
|
data/.gitignore
ADDED
@@ -0,0 +1,45 @@
|
|
1
|
+
*.gem
|
2
|
+
*.rbc
|
3
|
+
/.config
|
4
|
+
/coverage/
|
5
|
+
/InstalledFiles
|
6
|
+
/pkg/
|
7
|
+
/spec/reports/
|
8
|
+
/spec/examples.txt
|
9
|
+
/test/tmp/
|
10
|
+
/test/version_tmp/
|
11
|
+
/tmp/
|
12
|
+
|
13
|
+
# RSpec artifacts
|
14
|
+
.rspec_status
|
15
|
+
|
16
|
+
# Used by dotenv library to load environment variables.
|
17
|
+
.env
|
18
|
+
|
19
|
+
## Specific to RubyMotion:
|
20
|
+
.dat*
|
21
|
+
.repl_history
|
22
|
+
build/
|
23
|
+
*.bridgesupport
|
24
|
+
build-iPhoneOS/
|
25
|
+
build-iPhoneSimulator/
|
26
|
+
|
27
|
+
## Documentation cache and generated files:
|
28
|
+
/.yardoc/
|
29
|
+
/_yardoc/
|
30
|
+
/doc/
|
31
|
+
/rdoc/
|
32
|
+
|
33
|
+
## Environment normalization:
|
34
|
+
/.bundle/
|
35
|
+
/vendor/bundle
|
36
|
+
/lib/bundler/man/
|
37
|
+
|
38
|
+
# for a library or gem, you might want to ignore these files since the code is
|
39
|
+
# intended to run in multiple environments; otherwise, check them in:
|
40
|
+
Gemfile.lock
|
41
|
+
.ruby-version
|
42
|
+
.ruby-gemset
|
43
|
+
|
44
|
+
# unless supporting rvm < 1.11.0 or doing something fancy, ignore this:
|
45
|
+
.rvmrc
|
data/.rspec
ADDED
data/Gemfile
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
MIT License
|
2
|
+
|
3
|
+
Copyright (c) 2019 jahuty
|
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 all
|
13
|
+
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 THE
|
21
|
+
SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,47 @@
|
|
1
|
+
# snippets-ruby
|
2
|
+
Jahuty's Ruby client.
|
3
|
+
|
4
|
+
## Installation
|
5
|
+
|
6
|
+
Add this line to your application's `Gemfile`:
|
7
|
+
|
8
|
+
```ruby
|
9
|
+
gem 'jahuty-snippet'
|
10
|
+
```
|
11
|
+
|
12
|
+
And then execute:
|
13
|
+
|
14
|
+
$ bundle
|
15
|
+
|
16
|
+
Or install it yourself as:
|
17
|
+
|
18
|
+
$ gem install jahuty-snippets
|
19
|
+
|
20
|
+
## Usage
|
21
|
+
|
22
|
+
Set your public API key:
|
23
|
+
|
24
|
+
```ruby
|
25
|
+
Jahuty::Snippet.key = '1a2b3c4d5e1a2b3c4d5e'
|
26
|
+
```
|
27
|
+
|
28
|
+
Then, use the `.get` method to fetch a snippet:
|
29
|
+
|
30
|
+
```html+erb
|
31
|
+
<!doctype html>
|
32
|
+
<html>
|
33
|
+
<head>
|
34
|
+
<title>Ruby example</title>
|
35
|
+
</head>
|
36
|
+
<body>
|
37
|
+
<%= Jahuty::Snippet.get(123); %>
|
38
|
+
</body>
|
39
|
+
```
|
40
|
+
|
41
|
+
## Contributing
|
42
|
+
|
43
|
+
Bug reports and pull requests are welcome on [GitHub](https://github.com/jahuty/snippets-ruby).
|
44
|
+
|
45
|
+
## License
|
46
|
+
|
47
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "jahuty/snippets"
|
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,29 @@
|
|
1
|
+
|
2
|
+
lib = File.expand_path("../lib", __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require "jahuty/snippet/version"
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "jahuty-snippet"
|
8
|
+
spec.version = Jahuty::Snippet::VERSION
|
9
|
+
spec.authors = ["Jack Clayton"]
|
10
|
+
spec.email = ["jack@jahuty.com"]
|
11
|
+
|
12
|
+
spec.summary = %q{Jahuty's API client.}
|
13
|
+
spec.description = %q{Turn any page into a content-managed page.}
|
14
|
+
spec.homepage = "https://github.com/jahuty/snippets-ruby"
|
15
|
+
spec.license = "MIT"
|
16
|
+
|
17
|
+
spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
|
18
|
+
`git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
19
|
+
end
|
20
|
+
spec.bindir = "exe"
|
21
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
22
|
+
spec.require_paths = ["lib"]
|
23
|
+
|
24
|
+
spec.add_dependency 'faraday', '~> 0.1'
|
25
|
+
|
26
|
+
spec.add_development_dependency "bundler", "~> 2.0"
|
27
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
28
|
+
spec.add_development_dependency "rspec", "~> 3.0"
|
29
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
require "jahuty/snippet/data/problem"
|
2
|
+
require "jahuty/snippet/data/snippet"
|
3
|
+
require "jahuty/snippet/exception/not_ok"
|
4
|
+
require "jahuty/snippet/service/get"
|
5
|
+
require "jahuty/snippet/service/connect"
|
6
|
+
require "jahuty/snippet/version"
|
7
|
+
|
8
|
+
module Jahuty
|
9
|
+
module Snippet
|
10
|
+
@@key
|
11
|
+
@@get
|
12
|
+
|
13
|
+
def self.key=(key)
|
14
|
+
@@key = key
|
15
|
+
end
|
16
|
+
|
17
|
+
def self.get(id)
|
18
|
+
raise "API key not set. Did you use key=?" if @@key.nil?
|
19
|
+
|
20
|
+
@@get ||= Service::Get.new(Service::Connect.new.call(@@key))
|
21
|
+
|
22
|
+
snippet = @@get.call(id)
|
23
|
+
|
24
|
+
snippet.to_s
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
module Jahuty
|
2
|
+
module Snippet
|
3
|
+
module Data
|
4
|
+
class Problem
|
5
|
+
attr_accessor :status, :type, :detail
|
6
|
+
|
7
|
+
def initialize(status, type, detail)
|
8
|
+
@status = status
|
9
|
+
@type = type
|
10
|
+
@detail = detail
|
11
|
+
end
|
12
|
+
|
13
|
+
def self.from(data)
|
14
|
+
raise ArgumentError.new "Key :status does not exist" if !data.key?(:status)
|
15
|
+
raise ArgumentError.new "Key :type does not exist" if !data.key?(:type)
|
16
|
+
raise ArgumentError.new "Key :detail does not exist" if !data.key?(:detail)
|
17
|
+
|
18
|
+
Problem.new(data[:status], data[:type], data[:detail])
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
module Jahuty
|
2
|
+
module Snippet
|
3
|
+
module Data
|
4
|
+
class Snippet
|
5
|
+
attr_accessor :id, :content
|
6
|
+
|
7
|
+
def initialize(id, content)
|
8
|
+
@id = id
|
9
|
+
@content = content
|
10
|
+
end
|
11
|
+
|
12
|
+
def self.from(data)
|
13
|
+
raise ArgumentError.new "Key :id does not exist" if !data.key?(:id)
|
14
|
+
raise ArgumentError.new "Key :content does not exist" if !data.key?(:content)
|
15
|
+
|
16
|
+
Snippet.new(data[:id], data[:content])
|
17
|
+
end
|
18
|
+
|
19
|
+
def to_s
|
20
|
+
@content
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
module Jahuty
|
2
|
+
module Snippet
|
3
|
+
module Exception
|
4
|
+
class NotOk < ::StandardError
|
5
|
+
attr_reader :problem
|
6
|
+
|
7
|
+
def initialize(problem)
|
8
|
+
@problem = problem
|
9
|
+
end
|
10
|
+
|
11
|
+
def message
|
12
|
+
"The API responded with #{@problem.status}, #{@problem.type}: #{@problem.detail}"
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
require 'faraday'
|
2
|
+
|
3
|
+
module Jahuty
|
4
|
+
module Snippet
|
5
|
+
module Service
|
6
|
+
class Connect
|
7
|
+
URL = "https://www.jahuty.com/api/snippets"
|
8
|
+
|
9
|
+
HEADERS = {
|
10
|
+
"Accept": "application/json;q=0.9,*/*;q=0.8",
|
11
|
+
"Accept-Encoding": "gzip, deflate",
|
12
|
+
"Content-Type": "application/json; charset=utf-8",
|
13
|
+
"User-Agent": "Jahuty Ruby client #{::Jahuty::Snippet::VERSION}"
|
14
|
+
}
|
15
|
+
|
16
|
+
def call(key)
|
17
|
+
Faraday.new(
|
18
|
+
url: URL,
|
19
|
+
headers: {"Authorization": "Bearer #{key}"}.merge(HEADERS)
|
20
|
+
)
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
require 'json'
|
2
|
+
|
3
|
+
module Jahuty
|
4
|
+
module Snippet
|
5
|
+
module Service
|
6
|
+
class Get
|
7
|
+
@connection
|
8
|
+
|
9
|
+
def initialize(connection)
|
10
|
+
@connection = connection
|
11
|
+
|
12
|
+
end
|
13
|
+
|
14
|
+
def call(id)
|
15
|
+
response = @connection.get(id.to_s)
|
16
|
+
|
17
|
+
payload = JSON.parse(response.body, symbolize_names: true)
|
18
|
+
|
19
|
+
if response.status != 200
|
20
|
+
raise ::Jahuty::Snippet::Exception::NotOk.new(
|
21
|
+
::Jahuty::Snippet::Data::Problem.from(payload)
|
22
|
+
)
|
23
|
+
end
|
24
|
+
|
25
|
+
return ::Jahuty::Snippet::Data::Snippet.from(payload)
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
metadata
ADDED
@@ -0,0 +1,116 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: jahuty-snippet
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Jack Clayton
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2019-09-07 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: faraday
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0.1'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0.1'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: bundler
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '2.0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '2.0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rake
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '10.0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '10.0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rspec
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '3.0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '3.0'
|
69
|
+
description: Turn any page into a content-managed page.
|
70
|
+
email:
|
71
|
+
- jack@jahuty.com
|
72
|
+
executables: []
|
73
|
+
extensions: []
|
74
|
+
extra_rdoc_files: []
|
75
|
+
files:
|
76
|
+
- ".gitignore"
|
77
|
+
- ".rspec"
|
78
|
+
- Gemfile
|
79
|
+
- LICENSE
|
80
|
+
- README.md
|
81
|
+
- Rakefile
|
82
|
+
- bin/console
|
83
|
+
- bin/setup
|
84
|
+
- jahuty-snippets.gemspec
|
85
|
+
- lib/jahuty/snippet.rb
|
86
|
+
- lib/jahuty/snippet/data/problem.rb
|
87
|
+
- lib/jahuty/snippet/data/snippet.rb
|
88
|
+
- lib/jahuty/snippet/exception/not_ok.rb
|
89
|
+
- lib/jahuty/snippet/service/connect.rb
|
90
|
+
- lib/jahuty/snippet/service/get.rb
|
91
|
+
- lib/jahuty/snippet/version.rb
|
92
|
+
homepage: https://github.com/jahuty/snippets-ruby
|
93
|
+
licenses:
|
94
|
+
- MIT
|
95
|
+
metadata: {}
|
96
|
+
post_install_message:
|
97
|
+
rdoc_options: []
|
98
|
+
require_paths:
|
99
|
+
- lib
|
100
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
101
|
+
requirements:
|
102
|
+
- - ">="
|
103
|
+
- !ruby/object:Gem::Version
|
104
|
+
version: '0'
|
105
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
106
|
+
requirements:
|
107
|
+
- - ">="
|
108
|
+
- !ruby/object:Gem::Version
|
109
|
+
version: '0'
|
110
|
+
requirements: []
|
111
|
+
rubyforge_project:
|
112
|
+
rubygems_version: 2.7.8
|
113
|
+
signing_key:
|
114
|
+
specification_version: 4
|
115
|
+
summary: Jahuty's API client.
|
116
|
+
test_files: []
|