jahuty 1.1.2 → 2.0.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 8f74275c176fd1b733e7492f4524373bd93b86064d8339f8a7b78a6da25a735d
4
- data.tar.gz: ecde57318cafd32794680396be1cb4e157d84c56cec1d8ef180fabe313b74d97
3
+ metadata.gz: 9b9d03742760e8a4ef3d3a0e25d10c1d1327ee3604ce18333d1e65fe782724d1
4
+ data.tar.gz: 31b7447e69c911a50526675432d218514e2b71b577ad57848d7d644ba39fdba6
5
5
  SHA512:
6
- metadata.gz: 20ff6c3b514e40ca85f8cb54d885c75fc3ee1da81dfeb6f54ada4d87dba5706a16cd8ce0f5d2e5fb03d21fe9d749bbb1a2866901887fbf41cee0da17c6d6cbdf
7
- data.tar.gz: ca480ce882a777c2d5b9dfe9abb7ace46b6f3ad35e65391ba7cea0f7119b8ab436dfbf25cf4274b2406e80f1336c9d24ab52446ebb4e6fca457154cf8226f38b
6
+ metadata.gz: e75e3ec04864d5ef00f7ccf6887ed35dda5dcb7b7f817c2314c07bfa7b5579df6ae704cf8d92813d81f4a55eb86b1695d1288410298b60bb68dbb7ea8560e105
7
+ data.tar.gz: b453b5e32687e62dfbaf4ab62bd9463736c871e91fcbaeaecdc91afa738746823746c933974d86588719e1dd498e3f744020aa6f2955bece54e3c0c8f6f25924
@@ -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`, where `x` is the latest major version number:
10
+ Add this line to your application's `Gemfile`:
11
11
 
12
12
  ```ruby
13
- gem "jahuty", "~> 1.0"
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 `get()` method to retrieve a snippet:
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
- snippet = Snippet.get YOUR_SNIPPET_ID
38
+ render = Snippet.render YOUR_SNIPPET_ID
41
39
 
42
40
  # convert it to a string
43
- snippet.to_s
41
+ render.to_s
44
42
 
45
43
  # or, access its attributes
46
- snippet.id
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.get YOUR_SNIPPET_ID %>
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 with an optional second argument:
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.get(YOUR_SNIPPET_ID, {
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.get`, 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:
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.get YOUR_SNIPPET_ID
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
@@ -3,12 +3,12 @@ require "jahuty/version"
3
3
  require "jahuty/snippet"
4
4
 
5
5
  require "jahuty/data/problem"
6
- require "jahuty/data/snippet"
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/get"
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 Snippet
4
- attr_accessor :id, :content
3
+ class Render
4
+ attr_accessor :content
5
5
 
6
- def initialize(id, content)
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
- Snippet.new(data[:id], data[:content])
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::Get
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, params = {})
12
- options = { params: params.to_json } if !params.empty?
11
+ def call(id, options = {})
12
+ settings = { params: options[:params].to_json } unless options[:params].nil?
13
13
 
14
- response = @connection.get("snippets/#{id}", options || {})
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::Snippet.from(payload)
22
+ return Data::Render.from(payload)
23
23
  end
24
24
  end
25
25
  end
@@ -3,12 +3,12 @@ module Jahuty
3
3
  @get
4
4
 
5
5
  class << self
6
- def get(id, params = {})
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::Get.new(Service::Connect.new.call(Jahuty.key))
9
+ @get ||= Service::Render.new(Service::Connect.new.call(Jahuty.key))
10
10
 
11
- @get.call(id, params)
11
+ @get.call(id, options)
12
12
  end
13
13
  end
14
14
  end
@@ -1,3 +1,3 @@
1
1
  module Jahuty
2
- VERSION = "1.1.2"
2
+ VERSION = "2.0.0"
3
3
  end
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: 1.1.2
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/snippet.rb
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/get.rb
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