wordsmith-ruby-sdk 1.0.2

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGELOG.md ADDED
@@ -0,0 +1,39 @@
1
+ # Change Log
2
+ All notable changes to this project will be documented in this file. This project adheres to [Semantic Versioning](http://semver.org/).
3
+
4
+ ## [Unreleased](https://github.com/automatedinsightsinc/wordsmith-ruby-sdk/compare/v1.0.1...HEAD)
5
+
6
+ ## [1.0.2](https://github.com/AutomatedInsightsInc/wordsmith-ruby-sdk/tree/v1.0.1) - 2016-04-27
7
+ ##### Added
8
+ - Codeclimate test coverage reporter with dotenv for codeclimate token.
9
+ - Required ruby version in gemspec.
10
+
11
+ ##### Changed
12
+ - Gem version number bumped (missed bump in 1.0.0 release)
13
+
14
+ ## 1.0.0 - 2015-03-30
15
+
16
+ ##### Added
17
+ - Enabled test converage for generating output since encoding has been fixed on the api.
18
+ - A place to put a test token in `test/test_helper.rb`, should be Robert's token to match actual projects to test against.
19
+
20
+ ##### Changed
21
+ - Updated configuration default url to https://api.automatedinsights.com/v1
22
+ - Updated project generate output url to match routes in v1 api.
23
+
24
+ ## 0.0.2 - 2015-02-02
25
+
26
+ ##### Added
27
+ - Test coverage using minitest.
28
+ - Lots of README updates.
29
+ - CHANGELOG file.
30
+
31
+ ##### Removed
32
+ - Rails dependencies.
33
+ - Configuration through yaml file.
34
+
35
+ ##### Changed
36
+ - Configuration through conventional configuration methods.
37
+
38
+ ## 0.0.1 - 2015-01-21
39
+ - Prototype requiring railties.
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in wordsmith-sdk.gemspec
4
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,19 @@
1
+ Copyright (c) 2016, Automated Insights, Inc. All rights reserved.
2
+
3
+ You are hereby granted a non-exclusive, worldwide, royalty-free license to
4
+ use, copy, modify, and distribute this software in source code or binary
5
+ form for use in connection with the web services and APIs provided by
6
+ Automated Insights and its Wordsmith platform.
7
+
8
+ As with any software that integrates with the Wordsmith platform, your use
9
+ of this software is subject to the Wordsmith Terms of Service
10
+ [https://automatedinsights.com/terms-of-use/]. This copyright notice shall be included in all
11
+ copies or substantial portions of the software.
12
+
13
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
16
+ THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
18
+ FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
19
+ DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,47 @@
1
+ [![Code Climate](https://codeclimate.com/repos/5720c4b8e7b46b37e1002bfe/badges/3c997ae42848b5faf8ad/gpa.svg)](https://codeclimate.com/repos/5720c4b8e7b46b37e1002bfe/feed)
2
+ [![Test Coverage](https://codeclimate.com/repos/5720c4b8e7b46b37e1002bfe/badges/3c997ae42848b5faf8ad/coverage.svg)](https://codeclimate.com/repos/5720c4b8e7b46b37e1002bfe/coverage)
3
+ [![Issue Count](https://codeclimate.com/repos/5720c4b8e7b46b37e1002bfe/badges/3c997ae42848b5faf8ad/issue_count.svg)](https://codeclimate.com/repos/5720c4b8e7b46b37e1002bfe/feed)
4
+
5
+ # Wordsmith SDK for Ruby
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ ```ruby
12
+ gem 'wordsmith-ruby-sdk'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ $ bundle install
18
+
19
+
20
+ ## Configuration
21
+ Configure in initializer or as desired
22
+
23
+ ```ruby
24
+ #config/initializers/wordsmith.rb
25
+ Wordsmith.configure do |config|
26
+ config.token = MY_API_TOKEN
27
+ config.url = 'https://api.automatedinsights.com/v1' #optional, this is the default value
28
+ end
29
+ ```
30
+
31
+ ## Usage
32
+ ```ruby
33
+ projects = Wordsmith::Project.all #an array of projects your token can access
34
+ project = Wordsmith::Project.find('project-slug') #fetch a project by slug
35
+
36
+ project.schema #the data schema for the project
37
+ project.templates #a collection of templates for this project
38
+
39
+ template = project.templates.find('template-slug') #fetch a template by slug
40
+ template.generate({a_data_point: 1, another_one: 'Tuesday'}) #generate content
41
+ > {content: 'Your content is here!'}
42
+ ```
43
+
44
+ ## Contributing
45
+
46
+ Bug reports and pull requests are welcome on GitHub at https://github.com/automatedinsightsinc/wordsmith-ruby-sdk.
47
+
data/Rakefile ADDED
@@ -0,0 +1,10 @@
1
+ require "bundler/gem_tasks"
2
+ require 'rake/testtask'
3
+
4
+ task :default => :test
5
+
6
+ Rake::TestTask.new do |t|
7
+ t.libs << 'test'
8
+ t.test_files = FileList['test/*_test.rb']
9
+ # t.options = '--verbose'
10
+ end
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "wordsmith/sdk"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,6 @@
1
+ require 'wordsmith/version'
2
+ require 'wordsmith/project'
3
+ require 'wordsmith/template'
4
+ require 'wordsmith/template_collection'
5
+ require 'wordsmith/configuration'
6
+ require 'wordsmith/client'
@@ -0,0 +1,59 @@
1
+ require 'faraday'
2
+ require 'json'
3
+ require 'hashie'
4
+
5
+ module Wordsmith
6
+ class Client
7
+
8
+ def get(uri)
9
+ response = connection.get uri
10
+ parse_response response
11
+ end
12
+
13
+ def post(uri, data)
14
+ response = connection.post uri, {data: data}.to_json
15
+ parse_response response
16
+ end
17
+
18
+ private
19
+
20
+ def connection
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
+ })
27
+ end
28
+
29
+ def connection_valid?
30
+ return false unless @_connection
31
+ url = @_connection.url_prefix.to_s
32
+ authorization = @_connection.headers['Authorization']
33
+
34
+ url == Wordsmith.configuration.url &&
35
+ authorization == "Bearer #{Wordsmith.configuration.token}"
36
+ end
37
+
38
+ def parse_response(response)
39
+ body = JSON.parse(response.body)
40
+ Hashie.symbolize_keys! body
41
+ case response.status
42
+ when 200, 201
43
+ return body[:data]
44
+ when 400
45
+ fail %Q(Bad Request: "#{body[:error]}")
46
+ when 401
47
+ fail 'API authorization error'
48
+ else
49
+ fail 'API error'
50
+ end
51
+ end
52
+ end
53
+
54
+ module_function
55
+
56
+ def client
57
+ @_client ||= Client.new
58
+ end
59
+ end
@@ -0,0 +1,26 @@
1
+ module Wordsmith
2
+ class Configuration
3
+ attr_accessor :token, :url, :user_agent
4
+ DEFAULT_URL = 'https://api.automatedinsights.com/v1'
5
+ DEFAULT_USER_AGENT = "RubySDK/#{Wordsmith::VERSION}"
6
+
7
+ def initialize
8
+ @url = DEFAULT_URL
9
+ @user_agent = DEFAULT_USER_AGENT
10
+ end
11
+ end
12
+
13
+ module_function
14
+
15
+ def configuration
16
+ @_configuration ||= Configuration.new
17
+ end
18
+
19
+ def configure
20
+ yield configuration
21
+ end
22
+
23
+ def reset
24
+ @_configuration = Configuration.new
25
+ end
26
+ end
@@ -0,0 +1,31 @@
1
+ class Wordsmith::Project
2
+ attr_reader :name, :slug, :templates
3
+
4
+ def self.all
5
+ projects_attributes = Wordsmith.client.get 'projects'
6
+ projects_attributes.map {|p| new(**p)}
7
+ end
8
+
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
13
+
14
+ def schema
15
+ @_schema ||=
16
+ begin
17
+ body = Wordsmith.client.get "projects/#{slug}"
18
+ body[:schema]
19
+ end
20
+ end
21
+
22
+ private
23
+
24
+ def initialize(name: nil, slug: nil, templates: nil)
25
+ raise "Missing required kword arguments" unless [name, slug, templates].all?
26
+ @name = name
27
+ @slug = slug
28
+ @templates = Wordsmith::TemplateCollection.new(
29
+ templates.map {|t| Wordsmith::Template.new project: self, **t})
30
+ end
31
+ end
@@ -0,0 +1,14 @@
1
+ class Wordsmith::Template
2
+ attr_reader :name, :slug, :project
3
+
4
+ def initialize(name: nil, slug: nil, project: nil)
5
+ raise "Missing required kword arguments" unless [name, slug, project].all?
6
+ @name = name
7
+ @slug = slug
8
+ @project = project
9
+ end
10
+
11
+ def generate(data)
12
+ Wordsmith.client.post "projects/#{project.slug}/templates/#{slug}/outputs", data
13
+ end
14
+ end
@@ -0,0 +1,15 @@
1
+ class Wordsmith::TemplateCollection
2
+
3
+ def initialize(templates)
4
+ @templates = templates
5
+ end
6
+
7
+ def find(slug)
8
+ template = @templates.find {|t| t.slug == slug }
9
+ template or fail %Q(Template not found with slug: "#{slug}")
10
+ end
11
+
12
+ def all
13
+ @templates.dup
14
+ end
15
+ end
@@ -0,0 +1,3 @@
1
+ module Wordsmith
2
+ VERSION = '1.0.2'
3
+ end
@@ -0,0 +1,31 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'wordsmith/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "wordsmith-ruby-sdk"
8
+ spec.version = Wordsmith::VERSION
9
+ spec.authors = ["Robert Tillery"]
10
+ spec.email = ["rtillery@automatedinsights.com"]
11
+
12
+ spec.summary = %q{Wordsmith SDK for Ruby}
13
+ spec.description = %q{Provides API clients for Wordsmith.}
14
+ spec.homepage = "https://github.com/AutomatedInsightsInc/wordsmith-ruby-sdk"
15
+
16
+ spec.required_ruby_version = '~> 2.0'
17
+
18
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
19
+ spec.bindir = "exe"
20
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
21
+ spec.require_paths = ["lib"]
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"
28
+
29
+ spec.add_dependency 'faraday', '~> 0.9'
30
+ spec.add_dependency 'hashie', '~> 3.4'
31
+ end
metadata ADDED
@@ -0,0 +1,163 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: wordsmith-ruby-sdk
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.2
5
+ platform: ruby
6
+ authors:
7
+ - Robert Tillery
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2016-04-27 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.11'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.11'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: minitest
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '5.8'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '5.8'
55
+ - !ruby/object:Gem::Dependency
56
+ name: dotenv
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '2.1'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '2.1'
69
+ - !ruby/object:Gem::Dependency
70
+ name: codeclimate-test-reporter
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: faraday
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: '0.9'
90
+ type: :runtime
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: '0.9'
97
+ - !ruby/object:Gem::Dependency
98
+ name: hashie
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - "~>"
102
+ - !ruby/object:Gem::Version
103
+ version: '3.4'
104
+ type: :runtime
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - "~>"
109
+ - !ruby/object:Gem::Version
110
+ version: '3.4'
111
+ description: Provides API clients for Wordsmith.
112
+ email:
113
+ - rtillery@automatedinsights.com
114
+ executables: []
115
+ extensions: []
116
+ extra_rdoc_files: []
117
+ files:
118
+ - ".codeclimate.yml"
119
+ - ".csslintrc"
120
+ - ".env.example"
121
+ - ".eslintignore"
122
+ - ".eslintrc"
123
+ - ".gitignore"
124
+ - ".rubocop.yml"
125
+ - CHANGELOG.md
126
+ - Gemfile
127
+ - LICENSE
128
+ - README.md
129
+ - Rakefile
130
+ - bin/console
131
+ - bin/setup
132
+ - lib/wordsmith-ruby-sdk.rb
133
+ - lib/wordsmith/client.rb
134
+ - lib/wordsmith/configuration.rb
135
+ - lib/wordsmith/project.rb
136
+ - lib/wordsmith/template.rb
137
+ - lib/wordsmith/template_collection.rb
138
+ - lib/wordsmith/version.rb
139
+ - wordsmith-ruby-sdk.gemspec
140
+ homepage: https://github.com/AutomatedInsightsInc/wordsmith-ruby-sdk
141
+ licenses: []
142
+ metadata: {}
143
+ post_install_message:
144
+ rdoc_options: []
145
+ require_paths:
146
+ - lib
147
+ required_ruby_version: !ruby/object:Gem::Requirement
148
+ requirements:
149
+ - - "~>"
150
+ - !ruby/object:Gem::Version
151
+ version: '2.0'
152
+ required_rubygems_version: !ruby/object:Gem::Requirement
153
+ requirements:
154
+ - - ">="
155
+ - !ruby/object:Gem::Version
156
+ version: '0'
157
+ requirements: []
158
+ rubyforge_project:
159
+ rubygems_version: 2.5.1
160
+ signing_key:
161
+ specification_version: 4
162
+ summary: Wordsmith SDK for Ruby
163
+ test_files: []