jahuty 1.0.0 → 2.1.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/CHANGELOG.md +21 -0
- data/README.md +28 -13
- data/jahuty.gemspec +1 -1
- data/lib/jahuty.rb +2 -2
- data/lib/jahuty/data/{snippet.rb → render.rb} +4 -6
- data/lib/jahuty/service/connect.rb +1 -1
- data/lib/jahuty/service/{get.rb → render.rb} +6 -5
- data/lib/jahuty/snippet.rb +7 -5
- data/lib/jahuty/version.rb +1 -1
- metadata +7 -7
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a3b0216b333e26ac504fbc1a5329d13a8dbab1ec0de605fcb8ae8f8976bb728c
|
4
|
+
data.tar.gz: 6b9a6932abd413f52c4cba2b7e4bd4047b443ce625e25d2083a9f8c5d76c4f15
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4133af6f9a17eea018ce7ca98466ef631214160329d9aaaa42fe3272792391fc4c7deb166cafaa7c37491fc24502e7a5f494eaa93dc5f882fc65a95b216a089c
|
7
|
+
data.tar.gz: 6e7e074e20eda91bd5d000af585a4a46d3f9886a07dd3d24a9c4b811f78398787e116bca05e356eb591088ffd4ad4eef779fdff066c48fb4afd17b504b6d04db
|
data/CHANGELOG.md
CHANGED
@@ -5,6 +5,27 @@ All notable changes to this project will be documented in this file.
|
|
5
5
|
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
|
6
6
|
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
7
7
|
|
8
|
+
## 2.0.0 - 2020-07-04
|
9
|
+
|
10
|
+
- Change `Service::Get` to `Service::Render`.
|
11
|
+
- Change `Snippet.get` to `Snippet.render`.
|
12
|
+
- Change optional second argument of `Snippet.render` from `params` hash to options hash with `params` key.
|
13
|
+
- Change `Data::Snippet` to `Data::Render`.
|
14
|
+
- Remove `id` attribute from `Data::Render`.
|
15
|
+
- Change API endpoint to `snippets/:id/render`.
|
16
|
+
|
17
|
+
## 1.1.2 - 2020-07-04
|
18
|
+
|
19
|
+
- Change the Faraday gem from `~> 0.1` to `~> 1.0`.
|
20
|
+
|
21
|
+
## 1.1.1 - 2020-03-15
|
22
|
+
|
23
|
+
- Change snippet parameters to JSON query string parameter (e.g., `params={"foo":"bar"}`) from serialized query string parameter (e.g.,`params[foo]=bar`).
|
24
|
+
|
25
|
+
## 1.1.0 - 2020-03-14
|
26
|
+
|
27
|
+
- Add snippet parameters.
|
28
|
+
|
8
29
|
## 1.0.0 - 2020-03-08
|
9
30
|
|
10
31
|
- Update `rake` version.
|
data/README.md
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
# jahuty-ruby
|
2
|
-
Welcome [Jahuty's](https://www.jahuty.com) Ruby SDK!
|
2
|
+
Welcome to [Jahuty's](https://www.jahuty.com) Ruby SDK!
|
3
3
|
|
4
4
|
## Installation
|
5
5
|
|
@@ -7,10 +7,10 @@ This library requires [Ruby 2.3+](https://www.ruby-lang.org/en/downloads/release
|
|
7
7
|
|
8
8
|
It is multi-platform, and we strive to make it run equally well on Windows, Linux, and OSX.
|
9
9
|
|
10
|
-
Add this line to your application's `Gemfile
|
10
|
+
Add this line to your application's `Gemfile`:
|
11
11
|
|
12
12
|
```ruby
|
13
|
-
gem "jahuty", "~>
|
13
|
+
gem "jahuty", "~> 2.0"
|
14
14
|
```
|
15
15
|
|
16
16
|
And then execute:
|
@@ -29,22 +29,19 @@ require "jahuty"
|
|
29
29
|
Jahuty.key = "YOUR_API_KEY"
|
30
30
|
```
|
31
31
|
|
32
|
-
With the API key set, you can use the `
|
33
|
-
|
34
|
-
Then, use the `.get` method to fetch a snippet:
|
32
|
+
With the API key set, you can use the `Snippet.render` method to render a snippet:
|
35
33
|
|
36
34
|
```ruby
|
37
35
|
require "jahuty"
|
38
36
|
|
39
37
|
# retrieve the snippet
|
40
|
-
|
38
|
+
render = Snippet.render YOUR_SNIPPET_ID
|
41
39
|
|
42
40
|
# convert it to a string
|
43
|
-
|
41
|
+
render.to_s
|
44
42
|
|
45
43
|
# or, access its attributes
|
46
|
-
|
47
|
-
snippet.content
|
44
|
+
render.content
|
48
45
|
```
|
49
46
|
|
50
47
|
In an HTML view:
|
@@ -61,17 +58,35 @@ Jahuty.key = "YOUR_API_KEY"
|
|
61
58
|
<title>Awesome example</title>
|
62
59
|
</head>
|
63
60
|
<body>
|
64
|
-
<%= Snippet.
|
61
|
+
<%= Snippet.render YOUR_SNIPPET_ID %>
|
65
62
|
</body>
|
66
63
|
```
|
67
64
|
|
68
|
-
|
65
|
+
## Parameters
|
66
|
+
|
67
|
+
You can [pass parameters](https://www.jahuty.com/docs/passing-a-parameter) into your snippet using the `params` key of the options hash:
|
68
|
+
|
69
|
+
```ruby
|
70
|
+
require "jahuty"
|
71
|
+
|
72
|
+
Snippet.render(YOUR_SNIPPET_ID, params: { foo: "bar" });
|
73
|
+
```
|
74
|
+
|
75
|
+
The parameters above would be equivalent to [assigning the variables](https://www.jahuty.com/docs/assigning-a-variable) below in your snippet:
|
76
|
+
|
77
|
+
```html
|
78
|
+
{% assign foo = "bar" %}
|
79
|
+
```
|
80
|
+
|
81
|
+
## Errors
|
82
|
+
|
83
|
+
If you don't set your API key before calling `Snippet.render`, a `StandardError` will be raised. If an error occurs with [Jahuty's API](https://www.jahuty.com/docs/api), a `NotOk` exception will be raised:
|
69
84
|
|
70
85
|
```ruby
|
71
86
|
require "jahuty"
|
72
87
|
|
73
88
|
begin
|
74
|
-
Snippet.
|
89
|
+
Snippet.render YOUR_SNIPPET_ID
|
75
90
|
rescue StandardError => e
|
76
91
|
# hmm, did you set the API key first?
|
77
92
|
rescue Jahuty::Exception::NotOk => e
|
data/jahuty.gemspec
CHANGED
@@ -22,7 +22,7 @@ Gem::Specification.new do |spec|
|
|
22
22
|
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
23
23
|
spec.require_paths = ["lib"]
|
24
24
|
|
25
|
-
spec.add_dependency
|
25
|
+
spec.add_dependency "faraday", "~> 1.0"
|
26
26
|
|
27
27
|
spec.add_development_dependency "bundler", "~> 2.0"
|
28
28
|
spec.add_development_dependency "rake", "~> 12.3"
|
data/lib/jahuty.rb
CHANGED
@@ -3,12 +3,12 @@ require "jahuty/version"
|
|
3
3
|
require "jahuty/snippet"
|
4
4
|
|
5
5
|
require "jahuty/data/problem"
|
6
|
-
require "jahuty/data/
|
6
|
+
require "jahuty/data/render"
|
7
7
|
|
8
8
|
require "jahuty/exception/not_ok"
|
9
9
|
|
10
10
|
require "jahuty/service/connect"
|
11
|
-
require "jahuty/service/
|
11
|
+
require "jahuty/service/render"
|
12
12
|
|
13
13
|
module Jahuty
|
14
14
|
@key
|
@@ -1,18 +1,16 @@
|
|
1
1
|
module Jahuty
|
2
2
|
module Data
|
3
|
-
class
|
4
|
-
attr_accessor :
|
3
|
+
class Render
|
4
|
+
attr_accessor :content
|
5
5
|
|
6
|
-
def initialize(
|
7
|
-
@id = id
|
6
|
+
def initialize(content)
|
8
7
|
@content = content
|
9
8
|
end
|
10
9
|
|
11
10
|
def self.from(data)
|
12
|
-
raise ArgumentError.new "Key :id does not exist" if !data.key?(:id)
|
13
11
|
raise ArgumentError.new "Key :content does not exist" if !data.key?(:content)
|
14
12
|
|
15
|
-
|
13
|
+
Render.new(data[:content])
|
16
14
|
end
|
17
15
|
|
18
16
|
def to_s
|
@@ -1,16 +1,17 @@
|
|
1
1
|
require "json"
|
2
2
|
|
3
3
|
module Jahuty
|
4
|
-
class Service::
|
4
|
+
class Service::Render
|
5
5
|
@connection
|
6
6
|
|
7
7
|
def initialize(connection)
|
8
8
|
@connection = connection
|
9
|
-
|
10
9
|
end
|
11
10
|
|
12
|
-
def call(id)
|
13
|
-
|
11
|
+
def call(id, options = {})
|
12
|
+
settings = { params: options[:params].to_json } unless options[:params].nil?
|
13
|
+
|
14
|
+
response = @connection.get("snippets/#{id}/render", settings || {})
|
14
15
|
|
15
16
|
payload = JSON.parse(response.body, symbolize_names: true)
|
16
17
|
|
@@ -18,7 +19,7 @@ module Jahuty
|
|
18
19
|
raise Exception::NotOk.new(Data::Problem.from(payload))
|
19
20
|
end
|
20
21
|
|
21
|
-
return Data::
|
22
|
+
return Data::Render.from(payload)
|
22
23
|
end
|
23
24
|
end
|
24
25
|
end
|
data/lib/jahuty/snippet.rb
CHANGED
@@ -1,13 +1,15 @@
|
|
1
1
|
module Jahuty
|
2
2
|
class Snippet
|
3
|
-
|
3
|
+
@get
|
4
4
|
|
5
|
-
|
6
|
-
|
5
|
+
class << self
|
6
|
+
def render(id, options = {})
|
7
|
+
raise "API key not set. Did you use Jahuty.key?" unless Jahuty.key?
|
7
8
|
|
8
|
-
|
9
|
+
@get ||= Service::Render.new(Service::Connect.new.call(Jahuty.key))
|
9
10
|
|
10
|
-
|
11
|
+
@get.call(id, options)
|
12
|
+
end
|
11
13
|
end
|
12
14
|
end
|
13
15
|
end
|
data/lib/jahuty/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: jahuty
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0
|
4
|
+
version: 2.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jack Clayton
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-
|
11
|
+
date: 2020-07-28 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: faraday
|
@@ -16,14 +16,14 @@ dependencies:
|
|
16
16
|
requirements:
|
17
17
|
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: '0
|
19
|
+
version: '1.0'
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
24
|
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version: '0
|
26
|
+
version: '1.0'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: bundler
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
@@ -85,10 +85,10 @@ files:
|
|
85
85
|
- jahuty.gemspec
|
86
86
|
- lib/jahuty.rb
|
87
87
|
- lib/jahuty/data/problem.rb
|
88
|
-
- lib/jahuty/data/
|
88
|
+
- lib/jahuty/data/render.rb
|
89
89
|
- lib/jahuty/exception/not_ok.rb
|
90
90
|
- lib/jahuty/service/connect.rb
|
91
|
-
- lib/jahuty/service/
|
91
|
+
- lib/jahuty/service/render.rb
|
92
92
|
- lib/jahuty/snippet.rb
|
93
93
|
- lib/jahuty/version.rb
|
94
94
|
homepage: https://github.com/jahuty/jahuty-ruby
|
@@ -110,7 +110,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
110
110
|
- !ruby/object:Gem::Version
|
111
111
|
version: '0'
|
112
112
|
requirements: []
|
113
|
-
rubygems_version: 3.
|
113
|
+
rubygems_version: 3.1.4
|
114
114
|
signing_key:
|
115
115
|
specification_version: 4
|
116
116
|
summary: Jahuty's Ruby SDK.
|