jahuty 1.1.2 → 2.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +9 -0
- data/README.md +12 -25
- data/lib/jahuty.rb +2 -2
- data/lib/jahuty/data/{snippet.rb → render.rb} +4 -6
- data/lib/jahuty/service/{get.rb → render.rb} +5 -5
- data/lib/jahuty/snippet.rb +3 -3
- data/lib/jahuty/version.rb +1 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9b9d03742760e8a4ef3d3a0e25d10c1d1327ee3604ce18333d1e65fe782724d1
|
4
|
+
data.tar.gz: 31b7447e69c911a50526675432d218514e2b71b577ad57848d7d644ba39fdba6
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e75e3ec04864d5ef00f7ccf6887ed35dda5dcb7b7f817c2314c07bfa7b5579df6ae704cf8d92813d81f4a55eb86b1695d1288410298b60bb68dbb7ea8560e105
|
7
|
+
data.tar.gz: b453b5e32687e62dfbaf4ab62bd9463736c871e91fcbaeaecdc91afa738746823746c933974d86588719e1dd498e3f744020aa6f2955bece54e3c0c8f6f25924
|
data/CHANGELOG.md
CHANGED
@@ -5,6 +5,15 @@ 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
|
+
|
8
17
|
## 1.1.2 - 2020-07-04
|
9
18
|
|
10
19
|
- Change the Faraday gem from `~> 0.1` to `~> 1.0`.
|
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,45 +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
|
69
66
|
|
70
|
-
You can [pass parameters](https://www.jahuty.com/docs/passing-a-parameter) into your snippet
|
67
|
+
You can [pass parameters](https://www.jahuty.com/docs/passing-a-parameter) into your snippet using the `params` key of the options hash:
|
71
68
|
|
72
69
|
```ruby
|
73
70
|
require "jahuty"
|
74
71
|
|
75
|
-
Snippet.
|
76
|
-
foo: "bar",
|
77
|
-
baz: ["qux", "quux"],
|
78
|
-
corge: {
|
79
|
-
grault: {
|
80
|
-
garply: "waldo"
|
81
|
-
}
|
82
|
-
}
|
83
|
-
});
|
72
|
+
Snippet.render(YOUR_SNIPPET_ID, params: { foo: "bar" });
|
84
73
|
```
|
85
74
|
|
86
75
|
The parameters above would be equivalent to [assigning the variables](https://www.jahuty.com/docs/assigning-a-variable) below in your snippet:
|
87
76
|
|
88
77
|
```html
|
89
78
|
{% assign foo = "bar" %}
|
90
|
-
{% assign baz = ["qux", "quux"] %}
|
91
|
-
{% assign corge.grault.garply = "waldo" %}
|
92
79
|
```
|
93
80
|
|
94
81
|
## Errors
|
95
82
|
|
96
|
-
If you don't set your API key before calling `Snippet.
|
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:
|
97
84
|
|
98
85
|
```ruby
|
99
86
|
require "jahuty"
|
100
87
|
|
101
88
|
begin
|
102
|
-
Snippet.
|
89
|
+
Snippet.render YOUR_SNIPPET_ID
|
103
90
|
rescue StandardError => e
|
104
91
|
# hmm, did you set the API key first?
|
105
92
|
rescue Jahuty::Exception::NotOk => e
|
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,17 +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
9
|
end
|
10
10
|
|
11
|
-
def call(id,
|
12
|
-
|
11
|
+
def call(id, options = {})
|
12
|
+
settings = { params: options[:params].to_json } unless options[:params].nil?
|
13
13
|
|
14
|
-
response = @connection.get("snippets/#{id}",
|
14
|
+
response = @connection.get("snippets/#{id}/render", settings || {})
|
15
15
|
|
16
16
|
payload = JSON.parse(response.body, symbolize_names: true)
|
17
17
|
|
@@ -19,7 +19,7 @@ module Jahuty
|
|
19
19
|
raise Exception::NotOk.new(Data::Problem.from(payload))
|
20
20
|
end
|
21
21
|
|
22
|
-
return Data::
|
22
|
+
return Data::Render.from(payload)
|
23
23
|
end
|
24
24
|
end
|
25
25
|
end
|
data/lib/jahuty/snippet.rb
CHANGED
@@ -3,12 +3,12 @@ module Jahuty
|
|
3
3
|
@get
|
4
4
|
|
5
5
|
class << self
|
6
|
-
def
|
6
|
+
def render(id, options = {})
|
7
7
|
raise "API key not set. Did you use Jahuty.key?" unless Jahuty.key?
|
8
8
|
|
9
|
-
@get ||= Service::
|
9
|
+
@get ||= Service::Render.new(Service::Connect.new.call(Jahuty.key))
|
10
10
|
|
11
|
-
@get.call(id,
|
11
|
+
@get.call(id, options)
|
12
12
|
end
|
13
13
|
end
|
14
14
|
end
|
data/lib/jahuty/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: jahuty
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 2.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jack Clayton
|
@@ -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
|