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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 948fab3c8b8bda77a94f6a69efaf79d4529a2bd26d5183eea758e143bac819d6
4
- data.tar.gz: 0f8dfaf771f9d50926b1c8042da5e1a121c6f42ad0af5b2ba4879fd8d7663b67
3
+ metadata.gz: a3b0216b333e26ac504fbc1a5329d13a8dbab1ec0de605fcb8ae8f8976bb728c
4
+ data.tar.gz: 6b9a6932abd413f52c4cba2b7e4bd4047b443ce625e25d2083a9f8c5d76c4f15
5
5
  SHA512:
6
- metadata.gz: b8a73aa645e540e01355ebc3d75445cafe611b33e3e610bc3b327472f5ed608ea0839f21977348dd8d9a6b69b2c1369f450ae15a9ae7917103c1835e5da0bf1f
7
- data.tar.gz: dfe0afb290abd658c8a2fef352e36aa0141b63e17282bfb476b1829dd32229ffa157eb7b1ba40d77e084a2d3897a3b6cd304545f1058b95a44464f594a3f8a2f
6
+ metadata.gz: 4133af6f9a17eea018ce7ca98466ef631214160329d9aaaa42fe3272792391fc4c7deb166cafaa7c37491fc24502e7a5f494eaa93dc5f882fc65a95b216a089c
7
+ data.tar.gz: 6e7e074e20eda91bd5d000af585a4a46d3f9886a07dd3d24a9c4b811f78398787e116bca05e356eb591088ffd4ad4eef779fdff066c48fb4afd17b504b6d04db
@@ -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`, 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", "~> x"
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,17 +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
- 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:
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.get YOUR_SNIPPET_ID
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
@@ -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 'faraday', '~> 0.1'
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"
@@ -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
@@ -3,7 +3,7 @@ require "faraday"
3
3
  module Jahuty
4
4
  module Service
5
5
  class Connect
6
- URL = "https://www.jahuty.com/api/snippets"
6
+ URL = "https://api.jahuty.com"
7
7
 
8
8
  HEADERS = {
9
9
  "Accept": "application/json;q=0.9,*/*;q=0.8",
@@ -1,16 +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
-
10
9
  end
11
10
 
12
- def call(id)
13
- response = @connection.get(id.to_s)
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::Snippet.from(payload)
22
+ return Data::Render.from(payload)
22
23
  end
23
24
  end
24
25
  end
@@ -1,13 +1,15 @@
1
1
  module Jahuty
2
2
  class Snippet
3
- @@get
3
+ @get
4
4
 
5
- def self.get(id)
6
- raise "API key not set. Did you use Jahuty.key?" unless Jahuty.key?
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
- @@get ||= Service::Get.new(Service::Connect.new.call(Jahuty.key))
9
+ @get ||= Service::Render.new(Service::Connect.new.call(Jahuty.key))
9
10
 
10
- @@get.call(id)
11
+ @get.call(id, options)
12
+ end
11
13
  end
12
14
  end
13
15
  end
@@ -1,3 +1,3 @@
1
1
  module Jahuty
2
- VERSION = "1.0.0"
2
+ VERSION = "2.1.0"
3
3
  end
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.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-03-09 00:00:00.000000000 Z
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.1'
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.1'
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/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
@@ -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.0.3
113
+ rubygems_version: 3.1.4
114
114
  signing_key:
115
115
  specification_version: 4
116
116
  summary: Jahuty's Ruby SDK.