wordsmith-ruby-sdk 1.0.5 → 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 +4 -4
- data/.rubocop.yml +1 -58
- data/CHANGELOG.md +2 -3
- data/PULL_REQUEST_TEMPLATE.md +21 -0
- data/README.md +15 -8
- data/Rakefile +4 -0
- data/lib/wordsmith/client.rb +29 -23
- data/lib/wordsmith/configuration.rb +9 -3
- data/lib/wordsmith/project.rb +22 -18
- data/lib/wordsmith/template.rb +23 -11
- data/lib/wordsmith/template_collection.rb +1 -1
- data/lib/wordsmith/version.rb +1 -1
- data/wordsmith-ruby-sdk.gemspec +11 -11
- metadata +6 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e2edee3b154385fe36ade8499a071212527b1434
|
4
|
+
data.tar.gz: 3deb82adbe6a5d1baf0e5b35a59ef9d8cd42bb36
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7e4e68946fb9b84b1639e653ac105dfda79e9d9a9b89033fd1bad200f7c8ee0abce9ff0a92f983bf076cd60cff186b9c8e7b408637e60fd686b2478d77609dce
|
7
|
+
data.tar.gz: 92b41f79265180979fbd1234741c25419992d7f795dea0a3dc672a6b27f2744c17c35a96ceb7832deff417f4845145a5387cb625dabdb424110b7536919dc374
|
data/.rubocop.yml
CHANGED
@@ -313,58 +313,6 @@ Performance/StringReplacement:
|
|
313
313
|
Reference: 'https://github.com/JuanitoFatas/fast-ruby#stringgsub-vs-stringtr-code'
|
314
314
|
Enabled: true
|
315
315
|
|
316
|
-
##################### Rails ##################################
|
317
|
-
|
318
|
-
Rails/ActionFilter:
|
319
|
-
Description: 'Enforces consistent use of action filter methods.'
|
320
|
-
Enabled: false
|
321
|
-
|
322
|
-
Rails/Date:
|
323
|
-
Description: >-
|
324
|
-
Checks the correct usage of date aware methods,
|
325
|
-
such as Date.today, Date.current etc.
|
326
|
-
Enabled: false
|
327
|
-
|
328
|
-
Rails/Delegate:
|
329
|
-
Description: 'Prefer delegate method for delegations.'
|
330
|
-
Enabled: false
|
331
|
-
|
332
|
-
Rails/FindBy:
|
333
|
-
Description: 'Prefer find_by over where.first.'
|
334
|
-
Enabled: false
|
335
|
-
|
336
|
-
Rails/FindEach:
|
337
|
-
Description: 'Prefer all.find_each over all.find.'
|
338
|
-
Enabled: false
|
339
|
-
|
340
|
-
Rails/HasAndBelongsToMany:
|
341
|
-
Description: 'Prefer has_many :through to has_and_belongs_to_many.'
|
342
|
-
Enabled: false
|
343
|
-
|
344
|
-
Rails/Output:
|
345
|
-
Description: 'Checks for calls to puts, print, etc.'
|
346
|
-
Enabled: false
|
347
|
-
|
348
|
-
Rails/ReadWriteAttribute:
|
349
|
-
Description: >-
|
350
|
-
Checks for read_attribute(:attr) and
|
351
|
-
write_attribute(:attr, val).
|
352
|
-
Enabled: false
|
353
|
-
|
354
|
-
Rails/ScopeArgs:
|
355
|
-
Description: 'Checks the arguments of ActiveRecord scopes.'
|
356
|
-
Enabled: false
|
357
|
-
|
358
|
-
Rails/TimeZone:
|
359
|
-
Description: 'Checks the correct usage of time zone aware methods.'
|
360
|
-
StyleGuide: 'https://github.com/bbatsov/rails-style-guide#time'
|
361
|
-
Reference: 'http://danilenko.org/2012/7/6/rails_timezones'
|
362
|
-
Enabled: false
|
363
|
-
|
364
|
-
Rails/Validation:
|
365
|
-
Description: 'Use validates :attribute, hash of validations.'
|
366
|
-
Enabled: false
|
367
|
-
|
368
316
|
################## Style #################################
|
369
317
|
|
370
318
|
Style/AccessModifierIndentation:
|
@@ -528,11 +476,6 @@ Style/DefWithParentheses:
|
|
528
476
|
StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#method-parens'
|
529
477
|
Enabled: false
|
530
478
|
|
531
|
-
Style/DeprecatedHashMethods:
|
532
|
-
Description: 'Checks for use of deprecated Hash methods.'
|
533
|
-
StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#hash-key'
|
534
|
-
Enabled: false
|
535
|
-
|
536
479
|
Style/Documentation:
|
537
480
|
Description: 'Document classes and non-namespace modules.'
|
538
481
|
Enabled: false
|
@@ -716,7 +659,7 @@ Style/LineEndConcatenation:
|
|
716
659
|
line end.
|
717
660
|
Enabled: false
|
718
661
|
|
719
|
-
Style/
|
662
|
+
Style/MethodCallWithoutArgsParentheses:
|
720
663
|
Description: 'Do not use parentheses for method calls with no arguments.'
|
721
664
|
StyleGuide: 'https://github.com/bbatsov/ruby-style-guide#no-args-no-parens'
|
722
665
|
Enabled: false
|
data/CHANGELOG.md
CHANGED
@@ -1,8 +1,9 @@
|
|
1
1
|
# Change Log
|
2
2
|
All notable changes to this project will be documented in this file. This project adheres to [Semantic Versioning](http://semver.org/).
|
3
3
|
|
4
|
-
## [Unreleased](https://github.com/automatedinsightsinc/wordsmith-ruby-sdk/compare/v1.0.
|
4
|
+
## [Unreleased](https://github.com/automatedinsightsinc/wordsmith-ruby-sdk/compare/v1.0.5...HEAD)
|
5
5
|
|
6
|
+
##### Changed
|
6
7
|
## [1.0.5](https://github.com/automatedinsightsinc/wordsmith-ruby-sdk/compare/v1.0.4...v1.0.5)
|
7
8
|
##### Changed
|
8
9
|
- Return :errors from Wordsmith when HTTP response code is 400
|
@@ -20,8 +21,6 @@ All notable changes to this project will be documented in this file. This projec
|
|
20
21
|
##### Added
|
21
22
|
- Codeclimate test coverage reporter with dotenv for codeclimate token.
|
22
23
|
- Required ruby version in gemspec.
|
23
|
-
|
24
|
-
##### Changed
|
25
24
|
- Gem version number bumped (missed bump in 1.0.0 release)
|
26
25
|
|
27
26
|
## 1.0.0 - 2015-03-30
|
@@ -0,0 +1,21 @@
|
|
1
|
+
#### Background context for this PR
|
2
|
+
|
3
|
+
#### What does this PR do?
|
4
|
+
- [x] Something that's complete
|
5
|
+
- [ ] Something that's still in progress
|
6
|
+
|
7
|
+
#### Impacted areas in application
|
8
|
+
- A page affected
|
9
|
+
- A library affected
|
10
|
+
|
11
|
+
#### How should PR reviewers test this?
|
12
|
+
- Unit tests:
|
13
|
+
- `rake` (...OR replace with specific test files to run)
|
14
|
+
- Manual tests:
|
15
|
+
- What features need to be on or off?
|
16
|
+
- Detailed description of how to reproduce
|
17
|
+
- ...what page
|
18
|
+
- ...test data
|
19
|
+
- ...etc
|
20
|
+
|
21
|
+
#### Would you like specific feedback on anything?
|
data/README.md
CHANGED
@@ -39,20 +39,27 @@ Configure in initializer or as desired
|
|
39
39
|
#config/initializers/wordsmith.rb
|
40
40
|
Wordsmith.configure do |config|
|
41
41
|
config.token = MY_API_TOKEN
|
42
|
-
config.
|
42
|
+
config.version = '1' #optional, this is the default value
|
43
43
|
end
|
44
44
|
```
|
45
|
-
|
45
|
+
|
46
46
|
## Usage
|
47
47
|
```ruby
|
48
|
-
projects = Wordsmith::Project.all #
|
49
|
-
project = Wordsmith::Project.find('project-slug') #
|
48
|
+
projects = Wordsmith::Project.all # An array of projects your token can access
|
49
|
+
project = Wordsmith::Project.find('project-slug') # Fetch a project by slug
|
50
|
+
|
51
|
+
project.schema # The data schema for the project
|
52
|
+
project.templates # A collection of templates for this project
|
53
|
+
|
54
|
+
# Fetch a template by slug.
|
55
|
+
template = project.templates.find('template-slug')
|
50
56
|
|
51
|
-
|
52
|
-
|
57
|
+
# Test your implementation without being charged for producing content.
|
58
|
+
template.test({a_data_point: 1, another_one: 'Tuesday'})
|
59
|
+
> nil # if no errors found, otherwise return RuntimeError
|
53
60
|
|
54
|
-
|
55
|
-
template.generate({a_data_point: 1, another_one: 'Tuesday'}
|
61
|
+
# Generate your narrative.
|
62
|
+
template.generate({a_data_point: 1, another_one: 'Tuesday'}, proofread: false)
|
56
63
|
> {content: 'Your content is here!'}
|
57
64
|
```
|
58
65
|
|
data/Rakefile
CHANGED
data/lib/wordsmith/client.rb
CHANGED
@@ -6,24 +6,31 @@ module Wordsmith
|
|
6
6
|
class Client
|
7
7
|
|
8
8
|
def get(uri)
|
9
|
-
response = connection.get
|
10
|
-
parse_response
|
9
|
+
response = connection.get(uri)
|
10
|
+
parse_response(response)
|
11
11
|
end
|
12
12
|
|
13
|
-
def post(uri, data)
|
14
|
-
response = connection.post
|
15
|
-
parse_response
|
13
|
+
def post(uri, data, proofread:)
|
14
|
+
response = connection.post(uri, {data: data, proofread: proofread}.to_json)
|
15
|
+
parse_response(response)
|
16
16
|
end
|
17
17
|
|
18
18
|
private
|
19
19
|
|
20
20
|
def connection
|
21
21
|
return @_connection if connection_valid?
|
22
|
-
@_connection =
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
22
|
+
@_connection = initialize_connection
|
23
|
+
end
|
24
|
+
|
25
|
+
def initialize_connection
|
26
|
+
Faraday.new(
|
27
|
+
url: Wordsmith.configuration.url,
|
28
|
+
headers: {
|
29
|
+
'Content-Type' => 'application/json',
|
30
|
+
'Authorization' => "Bearer #{Wordsmith.configuration.token}",
|
31
|
+
'User-Agent' => Wordsmith.configuration.user_agent
|
32
|
+
}
|
33
|
+
)
|
27
34
|
end
|
28
35
|
|
29
36
|
def connection_valid?
|
@@ -31,24 +38,23 @@ module Wordsmith
|
|
31
38
|
url = @_connection.url_prefix.to_s
|
32
39
|
authorization = @_connection.headers['Authorization']
|
33
40
|
|
34
|
-
url == Wordsmith.configuration.url &&
|
35
|
-
|
41
|
+
url == Wordsmith.configuration.url && valid_token?(authorization)
|
42
|
+
end
|
43
|
+
|
44
|
+
def valid_token?(authorization)
|
45
|
+
authorization == "Bearer #{Wordsmith.configuration.token}"
|
36
46
|
end
|
37
47
|
|
38
48
|
def parse_response(response)
|
39
49
|
body = JSON.parse(response.body)
|
40
|
-
Hashie.symbolize_keys!
|
50
|
+
Hashie.symbolize_keys!(body)
|
41
51
|
case response.status
|
42
|
-
when 200, 201
|
43
|
-
|
44
|
-
when
|
45
|
-
|
46
|
-
when
|
47
|
-
|
48
|
-
when 429
|
49
|
-
fail body[:error]
|
50
|
-
else
|
51
|
-
fail 'API error'
|
52
|
+
when 200, 201 then body[:data]
|
53
|
+
when 400 then raise(%Q(Bad Request: "#{body[:errors]}"))
|
54
|
+
when 401 then raise('API authorization error.')
|
55
|
+
when 404 then raise('Incorrect version set in wordsmith.rb')
|
56
|
+
when 429 then raise(body[:error])
|
57
|
+
else raise('API error')
|
52
58
|
end
|
53
59
|
end
|
54
60
|
end
|
@@ -1,13 +1,19 @@
|
|
1
1
|
module Wordsmith
|
2
2
|
class Configuration
|
3
|
-
attr_accessor :token, :
|
4
|
-
|
3
|
+
attr_accessor :token, :user_agent, :version
|
4
|
+
DEFAULT_VERSION = '1'
|
5
5
|
DEFAULT_USER_AGENT = "RubySDK/#{Wordsmith::VERSION}"
|
6
|
+
URL_HOST = 'https://api.automatedinsights.com'
|
7
|
+
DEFAULT_URL = "#{URL_HOST}/v#{DEFAULT_VERSION}"
|
6
8
|
|
7
9
|
def initialize
|
8
|
-
@
|
10
|
+
@version = DEFAULT_VERSION
|
9
11
|
@user_agent = DEFAULT_USER_AGENT
|
10
12
|
end
|
13
|
+
|
14
|
+
def url
|
15
|
+
"#{URL_HOST}/v#{version}"
|
16
|
+
end
|
11
17
|
end
|
12
18
|
|
13
19
|
module_function
|
data/lib/wordsmith/project.rb
CHANGED
@@ -1,24 +1,28 @@
|
|
1
|
-
|
2
|
-
|
1
|
+
module Wordsmith
|
2
|
+
class Project
|
3
|
+
attr_reader :name, :slug, :schema, :templates
|
3
4
|
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
5
|
+
def self.all
|
6
|
+
projects_attributes = Wordsmith.client.get('projects')
|
7
|
+
projects_attributes.map {|p| new(**p)}
|
8
|
+
end
|
8
9
|
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
10
|
+
def self.find(slug)
|
11
|
+
project = all.find { |p| p.slug == slug }
|
12
|
+
project || raise(%Q(Project not found with slug: "#{slug}"))
|
13
|
+
end
|
13
14
|
|
14
|
-
|
15
|
+
private
|
15
16
|
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
17
|
+
def initialize(name: nil, slug: nil, schema: nil, templates: nil, **attributes)
|
18
|
+
raise 'Missing required keyword arguments' unless [name, slug, templates].all?
|
19
|
+
@name = name
|
20
|
+
@slug = slug
|
21
|
+
@schema = schema
|
22
|
+
@templates =
|
23
|
+
Wordsmith::TemplateCollection.new(
|
24
|
+
templates.map { |t| Wordsmith::Template.new(project: self, **t) }
|
25
|
+
)
|
26
|
+
end
|
23
27
|
end
|
24
28
|
end
|
data/lib/wordsmith/template.rb
CHANGED
@@ -1,14 +1,26 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
1
|
+
module Wordsmith
|
2
|
+
class Template
|
3
|
+
attr_reader :name, :slug, :project
|
4
|
+
|
5
|
+
def initialize(name: nil, slug: nil, project: nil, **attributes)
|
6
|
+
raise 'Missing required keyword arguments' unless [name, slug, project].all?
|
7
|
+
@name = name
|
8
|
+
@slug = slug
|
9
|
+
@project = project
|
10
|
+
end
|
11
|
+
|
12
|
+
def generate(data, proofread: false)
|
13
|
+
Wordsmith.client.post(path('outputs'), data, proofread: proofread)
|
14
|
+
end
|
15
|
+
|
16
|
+
def test(data, proofread: false)
|
17
|
+
Wordsmith.client.post(path('test'), data, proofread: proofread)
|
18
|
+
end
|
19
|
+
|
20
|
+
private
|
10
21
|
|
11
|
-
|
12
|
-
|
22
|
+
def path(endpoint)
|
23
|
+
"projects/#{project.slug}/templates/#{slug}/#{endpoint}"
|
24
|
+
end
|
13
25
|
end
|
14
26
|
end
|
data/lib/wordsmith/version.rb
CHANGED
data/wordsmith-ruby-sdk.gemspec
CHANGED
@@ -4,27 +4,27 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
|
4
4
|
require 'wordsmith/version'
|
5
5
|
|
6
6
|
Gem::Specification.new do |spec|
|
7
|
-
spec.name =
|
7
|
+
spec.name = 'wordsmith-ruby-sdk'
|
8
8
|
spec.version = Wordsmith::VERSION
|
9
|
-
spec.authors = [
|
10
|
-
spec.email = [
|
9
|
+
spec.authors = ['Robert Tillery', 'Jonathan Gaegler']
|
10
|
+
spec.email = ['jong@automatedinsights.com']
|
11
11
|
|
12
12
|
spec.summary = %q{Wordsmith SDK for Ruby}
|
13
13
|
spec.description = %q{Provides API clients for Wordsmith.}
|
14
|
-
spec.homepage =
|
14
|
+
spec.homepage = 'https://github.com/AutomatedInsightsInc/wordsmith-ruby-sdk'
|
15
15
|
|
16
16
|
spec.required_ruby_version = '~> 2.0'
|
17
17
|
|
18
18
|
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
19
|
-
spec.bindir =
|
19
|
+
spec.bindir = 'exe'
|
20
20
|
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
21
|
-
spec.require_paths = [
|
21
|
+
spec.require_paths = ['lib']
|
22
22
|
|
23
|
-
spec.add_development_dependency
|
24
|
-
spec.add_development_dependency
|
25
|
-
spec.add_development_dependency
|
26
|
-
spec.add_development_dependency
|
27
|
-
spec.add_development_dependency
|
23
|
+
spec.add_development_dependency 'bundler', '~> 1.11'
|
24
|
+
spec.add_development_dependency 'rake', '~> 10.0'
|
25
|
+
spec.add_development_dependency 'minitest', '~> 5.8'
|
26
|
+
spec.add_development_dependency 'dotenv', '~> 2.1'
|
27
|
+
spec.add_development_dependency 'codeclimate-test-reporter', '~> 0'
|
28
28
|
|
29
29
|
spec.add_dependency 'faraday', '~> 0.9'
|
30
30
|
spec.add_dependency 'hashie', '~> 3.4'
|
metadata
CHANGED
@@ -1,14 +1,15 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: wordsmith-ruby-sdk
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 2.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Robert Tillery
|
8
|
+
- Jonathan Gaegler
|
8
9
|
autorequire:
|
9
10
|
bindir: exe
|
10
11
|
cert_chain: []
|
11
|
-
date:
|
12
|
+
date: 2017-05-30 00:00:00.000000000 Z
|
12
13
|
dependencies:
|
13
14
|
- !ruby/object:Gem::Dependency
|
14
15
|
name: bundler
|
@@ -110,7 +111,7 @@ dependencies:
|
|
110
111
|
version: '3.4'
|
111
112
|
description: Provides API clients for Wordsmith.
|
112
113
|
email:
|
113
|
-
-
|
114
|
+
- jong@automatedinsights.com
|
114
115
|
executables: []
|
115
116
|
extensions: []
|
116
117
|
extra_rdoc_files: []
|
@@ -125,6 +126,7 @@ files:
|
|
125
126
|
- CHANGELOG.md
|
126
127
|
- Gemfile
|
127
128
|
- LICENSE
|
129
|
+
- PULL_REQUEST_TEMPLATE.md
|
128
130
|
- README.md
|
129
131
|
- Rakefile
|
130
132
|
- bin/console
|
@@ -156,7 +158,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
156
158
|
version: '0'
|
157
159
|
requirements: []
|
158
160
|
rubyforge_project:
|
159
|
-
rubygems_version: 2.
|
161
|
+
rubygems_version: 2.5.2
|
160
162
|
signing_key:
|
161
163
|
specification_version: 4
|
162
164
|
summary: Wordsmith SDK for Ruby
|