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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: e04d2f0401f1753648c5cff6a9bcf95d4c712eba
4
- data.tar.gz: 5142657050d39066695ee10c2ad8453c961ae22f
3
+ metadata.gz: e2edee3b154385fe36ade8499a071212527b1434
4
+ data.tar.gz: 3deb82adbe6a5d1baf0e5b35a59ef9d8cd42bb36
5
5
  SHA512:
6
- metadata.gz: bf191499ee860d310551d10be52aa6c345f6d99a86a79d616605078309cc709f1af1fe5d303bbbfd1d2c1b53aa1d8b4265bd7ed0773d78411ba007362e78e063
7
- data.tar.gz: 6601d1f7dd3b14d310b5d27afa96ef8eda5966b05f04b440a5e98cb4e9534c44998ea97463279fc0621aaa6a6253f6858beba3526703c1433ee89f5eaaee2ef5
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/MethodCallParentheses:
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...HEAD)
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.url = 'https://api.automatedinsights.com/v1' #optional, this is the default value
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 #an array of projects your token can access
49
- project = Wordsmith::Project.find('project-slug') #fetch a project by 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
- project.schema #the data schema for the project
52
- project.templates #a collection of templates for this project
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
- template = project.templates.find('template-slug') #fetch a template by slug
55
- template.generate({a_data_point: 1, another_one: 'Tuesday'}) #generate content
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
@@ -8,3 +8,7 @@ Rake::TestTask.new do |t|
8
8
  t.test_files = FileList['test/*_test.rb']
9
9
  # t.options = '--verbose'
10
10
  end
11
+
12
+ task :console do
13
+ exec "irb -r wordsmith-ruby-sdk -I ./lib"
14
+ end
@@ -6,24 +6,31 @@ module Wordsmith
6
6
  class Client
7
7
 
8
8
  def get(uri)
9
- response = connection.get uri
10
- parse_response response
9
+ response = connection.get(uri)
10
+ parse_response(response)
11
11
  end
12
12
 
13
- def post(uri, data)
14
- response = connection.post uri, {data: data}.to_json
15
- parse_response 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 = Faraday.new(url: Wordsmith.configuration.url, headers: {
23
- 'Content-Type' => 'application/json',
24
- 'Authorization' => "Bearer #{Wordsmith.configuration.token}",
25
- 'User-Agent' => Wordsmith.configuration.user_agent
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
- authorization == "Bearer #{Wordsmith.configuration.token}"
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! body
50
+ Hashie.symbolize_keys!(body)
41
51
  case response.status
42
- when 200, 201
43
- return body[:data]
44
- when 400
45
- fail %Q(Bad Request: "#{body[:errors]}")
46
- when 401
47
- fail 'API authorization error'
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, :url, :user_agent
4
- DEFAULT_URL = 'https://api.automatedinsights.com/v1'
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
- @url = DEFAULT_URL
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
@@ -1,24 +1,28 @@
1
- class Wordsmith::Project
2
- attr_reader :name, :slug, :schema, :templates
1
+ module Wordsmith
2
+ class Project
3
+ attr_reader :name, :slug, :schema, :templates
3
4
 
4
- def self.all
5
- projects_attributes = Wordsmith.client.get 'projects'
6
- projects_attributes.map {|p| new(**p)}
7
- end
5
+ def self.all
6
+ projects_attributes = Wordsmith.client.get('projects')
7
+ projects_attributes.map {|p| new(**p)}
8
+ end
8
9
 
9
- def self.find(slug)
10
- project = all.find { |p| p.slug == slug }
11
- project or fail %Q(Project not found with slug: "#{slug}")
12
- end
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
- private
15
+ private
15
16
 
16
- def initialize(name: nil, slug: nil, schema: nil, templates: nil, **attributes)
17
- raise "Missing required keyword arguments" unless [name, slug, templates].all?
18
- @name = name
19
- @slug = slug
20
- @schema = schema
21
- @templates = Wordsmith::TemplateCollection.new(
22
- templates.map {|t| Wordsmith::Template.new project: self, **t})
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
@@ -1,14 +1,26 @@
1
- class Wordsmith::Template
2
- attr_reader :name, :slug, :project
3
-
4
- def initialize(name: nil, slug: nil, project: nil, **attributes)
5
- raise "Missing required keyword arguments" unless [name, slug, project].all?
6
- @name = name
7
- @slug = slug
8
- @project = project
9
- end
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
- def generate(data)
12
- Wordsmith.client.post "projects/#{project.slug}/templates/#{slug}/outputs", data
22
+ def path(endpoint)
23
+ "projects/#{project.slug}/templates/#{slug}/#{endpoint}"
24
+ end
13
25
  end
14
26
  end
@@ -6,7 +6,7 @@ class Wordsmith::TemplateCollection
6
6
 
7
7
  def find(slug)
8
8
  template = @templates.find {|t| t.slug == slug }
9
- template or fail %Q(Template not found with slug: "#{slug}")
9
+ template || raise(%Q(Template not found with slug: "#{slug}"))
10
10
  end
11
11
 
12
12
  def all
@@ -1,3 +1,3 @@
1
1
  module Wordsmith
2
- VERSION = '1.0.5'
2
+ VERSION = '2.0.0'
3
3
  end
@@ -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 = "wordsmith-ruby-sdk"
7
+ spec.name = 'wordsmith-ruby-sdk'
8
8
  spec.version = Wordsmith::VERSION
9
- spec.authors = ["Robert Tillery"]
10
- spec.email = ["rtillery@automatedinsights.com"]
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 = "https://github.com/AutomatedInsightsInc/wordsmith-ruby-sdk"
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 = "exe"
19
+ spec.bindir = 'exe'
20
20
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
21
- spec.require_paths = ["lib"]
21
+ spec.require_paths = ['lib']
22
22
 
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"
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: 1.0.5
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: 2016-11-11 00:00:00.000000000 Z
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
- - rtillery@automatedinsights.com
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.6.4
161
+ rubygems_version: 2.5.2
160
162
  signing_key:
161
163
  specification_version: 4
162
164
  summary: Wordsmith SDK for Ruby