yext-api 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +25 -0
- data/.rspec +3 -0
- data/.rubocop.yml +100 -0
- data/.ruby-version +1 -0
- data/.travis.yml +5 -0
- data/CODE_OF_CONDUCT.md +74 -0
- data/Gemfile +10 -0
- data/Gemfile.lock +187 -0
- data/LICENSE.txt +21 -0
- data/README.md +206 -0
- data/Rakefile +30 -0
- data/app/assets/config/yext_api_manifest.js +2 -0
- data/app/assets/images/yext/api/.keep +0 -0
- data/app/assets/javascripts/yext/api/application.js +13 -0
- data/app/assets/stylesheets/yext/api/application.css +15 -0
- data/app/controllers/yext/api/application_controller.rb +12 -0
- data/app/docs/notes.txt +45 -0
- data/app/helpers/yext/api/application_helper.rb +11 -0
- data/app/jobs/yext/api/application_job.rb +8 -0
- data/app/mailers/yext/api/application_mailer.rb +11 -0
- data/app/models/yext/api/application_record.rb +10 -0
- data/app/views/layouts/yext/api/application.html.erb +14 -0
- data/bin/console +16 -0
- data/bin/rails +16 -0
- data/bin/setup +8 -0
- data/config/initializers/spyke.rb +3 -0
- data/config/routes.rb +4 -0
- data/lib/config/api.yml +1100 -0
- data/lib/tasks/yext/api_tasks.rake +6 -0
- data/lib/yext/api.rb +33 -0
- data/lib/yext/api/administrative_api.rb +12 -0
- data/lib/yext/api/administrative_api/account.rb +62 -0
- data/lib/yext/api/administrative_api/add_request.rb +34 -0
- data/lib/yext/api/administrative_api/service.rb +38 -0
- data/lib/yext/api/concerns/account_child.rb +92 -0
- data/lib/yext/api/concerns/account_relations.rb +25 -0
- data/lib/yext/api/concerns/api_finder.rb +61 -0
- data/lib/yext/api/concerns/default_scopes.rb +37 -0
- data/lib/yext/api/concerns/enum_all.rb +18 -0
- data/lib/yext/api/concerns/faraday_connection.rb +45 -0
- data/lib/yext/api/concerns/rate_limits.rb +31 -0
- data/lib/yext/api/engine.rb +13 -0
- data/lib/yext/api/enumerations/validation.rb +16 -0
- data/lib/yext/api/knowledge_api.rb +12 -0
- data/lib/yext/api/knowledge_api/account_settings/account.rb +33 -0
- data/lib/yext/api/knowledge_api/health_check/health.rb +25 -0
- data/lib/yext/api/knowledge_api/knowledge_manager/category.rb +25 -0
- data/lib/yext/api/knowledge_api/knowledge_manager/location.rb +59 -0
- data/lib/yext/api/live_api.rb +12 -0
- data/lib/yext/api/live_api/location.rb +37 -0
- data/lib/yext/api/utils/api_base.rb +13 -0
- data/lib/yext/api/utils/api_rate_limits.rb +36 -0
- data/lib/yext/api/utils/configuration.rb +97 -0
- data/lib/yext/api/utils/default_parameters.rb +57 -0
- data/lib/yext/api/utils/response_parser.rb +84 -0
- data/lib/yext/api/version.rb +7 -0
- data/lib/yext/include_rails.rb +31 -0
- data/yext-api.gemspec +51 -0
- metadata +271 -0
@@ -0,0 +1,84 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Yext
|
4
|
+
module Api
|
5
|
+
module Utils
|
6
|
+
# The default response parser for Faraday to get the results from Yext into the structure
|
7
|
+
# that is needed by Spyke.
|
8
|
+
class ResponseParser < Faraday::Response::Middleware
|
9
|
+
include Yext::Api::Concerns::ApiFinder
|
10
|
+
|
11
|
+
def call(env)
|
12
|
+
@parse_env = env
|
13
|
+
|
14
|
+
@app.call(env).on_complete do |environment|
|
15
|
+
on_complete(environment)
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
def parse(body)
|
20
|
+
# Yext Response:
|
21
|
+
# http://developer.yext.com/docs/api-reference/#section/Policies-and-Conventions
|
22
|
+
#
|
23
|
+
# Example response format:
|
24
|
+
# {
|
25
|
+
# "meta": {
|
26
|
+
# "uuid": "bb0c7e19-4dc3-4891-bfa5-8593b1f124ad",
|
27
|
+
# "errors": [
|
28
|
+
# {
|
29
|
+
# "code": ...error code...,
|
30
|
+
# "type": ...error, fatal error, non fatal error, or warning...,
|
31
|
+
# "message": ...explanation of the issue...
|
32
|
+
# }
|
33
|
+
# ]
|
34
|
+
# },
|
35
|
+
# "response": {
|
36
|
+
# ...results...
|
37
|
+
# }
|
38
|
+
# }
|
39
|
+
#
|
40
|
+
# Spyke Expected Response Format:
|
41
|
+
# https://github.com/balvig/spyke#configuration
|
42
|
+
#
|
43
|
+
# { data: { id: 1, name: 'Bob' }, metadata: {}, errors: {} }
|
44
|
+
#
|
45
|
+
# Errors:
|
46
|
+
# https://github.com/balvig/spyke#api-side-validations
|
47
|
+
#
|
48
|
+
# { title: [{ error: 'blank'}, { error: 'too_short', count: 10 }]}
|
49
|
+
|
50
|
+
# yext_response_json = MultiJson.load(body, symbolize_keys: true)
|
51
|
+
return {} if body.starts_with?("<html")
|
52
|
+
return { data: [{ response_string: body }], metadata: {}, errors: {} } unless body.starts_with?("{")
|
53
|
+
|
54
|
+
yext_response_json = JSON.parse(body, symbolize_names: true)
|
55
|
+
|
56
|
+
data = extract_data_value(yext_response_json)
|
57
|
+
|
58
|
+
save_meta_data(find_api(parse_env[:url], parse_env[:method].to_s), yext_response_json[:meta])
|
59
|
+
|
60
|
+
{ data: data,
|
61
|
+
metadata: yext_response_json[:meta],
|
62
|
+
errors: {} }
|
63
|
+
end
|
64
|
+
|
65
|
+
private
|
66
|
+
|
67
|
+
def extract_data_value(yext_response_json)
|
68
|
+
data = yext_response_json[:response]
|
69
|
+
data = data[(data.keys - [:count]).first] if data.is_a?(Hash) && (data.key?(:count) || data.length <= 2)
|
70
|
+
|
71
|
+
data
|
72
|
+
end
|
73
|
+
|
74
|
+
attr_reader :parse_env
|
75
|
+
|
76
|
+
def save_meta_data(api_module, metadata)
|
77
|
+
return if api_module.blank?
|
78
|
+
|
79
|
+
api_module.last_meta = metadata
|
80
|
+
end
|
81
|
+
end
|
82
|
+
end
|
83
|
+
end
|
84
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# Code in this file is copied from `require "rails/all"`
|
4
|
+
|
5
|
+
RAILS_ALL = %w[active_record/railtie
|
6
|
+
action_controller/railtie
|
7
|
+
action_view/railtie
|
8
|
+
action_mailer/railtie
|
9
|
+
active_job/railtie
|
10
|
+
action_cable/engine
|
11
|
+
rails/test_unit/railtie
|
12
|
+
sprockets/railtie].freeze
|
13
|
+
|
14
|
+
# Yext is not using these elements of Rails yet. Remove them.
|
15
|
+
RAILS_USED = RAILS_ALL - %w[active_record/railtie
|
16
|
+
action_view/railtie
|
17
|
+
action_mailer/railtie
|
18
|
+
active_job/railtie
|
19
|
+
action_cable/engine
|
20
|
+
rails/test_unit/railtie
|
21
|
+
sprockets/railtie].freeze
|
22
|
+
|
23
|
+
RAILS_USED.each do |railtie|
|
24
|
+
begin
|
25
|
+
require railtie
|
26
|
+
rescue LoadError => e
|
27
|
+
# :nocov:
|
28
|
+
Rails.logger.error e
|
29
|
+
# :nocov:
|
30
|
+
end
|
31
|
+
end
|
data/yext-api.gemspec
ADDED
@@ -0,0 +1,51 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# rubocop:disable BlockLength
|
4
|
+
|
5
|
+
lib = File.expand_path("../lib", __FILE__)
|
6
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
7
|
+
require "yext/api/version"
|
8
|
+
|
9
|
+
Gem::Specification.new do |spec|
|
10
|
+
spec.name = "yext-api"
|
11
|
+
spec.version = Yext::Api::VERSION
|
12
|
+
spec.authors = ["CardTapp"]
|
13
|
+
spec.email = ["dustin@cardtapp.com"]
|
14
|
+
|
15
|
+
spec.summary = "An interface gem to the Yext API."
|
16
|
+
spec.description = "A straightforward simple interface with the Yext API v2."
|
17
|
+
spec.homepage = "https://github.com/CardTapp/yext-api"
|
18
|
+
spec.license = "MIT"
|
19
|
+
|
20
|
+
# Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
|
21
|
+
# to allow pushing to a single host or delete this section to allow pushing to any host.
|
22
|
+
raise "RubyGems 2.0 or newer is required to protect against public gem pushes." unless spec.respond_to?(:metadata)
|
23
|
+
|
24
|
+
spec.metadata["allowed_push_host"] = "https://rubygems.org"
|
25
|
+
|
26
|
+
spec.files = `git ls-files -z`.split("\x0").reject do |f|
|
27
|
+
f.match(%r{^(test|spec|features)/})
|
28
|
+
end
|
29
|
+
|
30
|
+
spec.bindir = "exe"
|
31
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
32
|
+
spec.require_paths = ["lib"]
|
33
|
+
|
34
|
+
spec.add_dependency "rails", "~> 5.1.2"
|
35
|
+
spec.add_dependency "spyke", "~> 5"
|
36
|
+
|
37
|
+
spec.add_development_dependency "bundler", "~> 1.16"
|
38
|
+
spec.add_development_dependency "cornucopia"
|
39
|
+
# spec.add_development_dependency "dotenv", "~> 2.0"
|
40
|
+
# spec.add_development_dependency "dotenv-rails"
|
41
|
+
spec.add_development_dependency "hashie"
|
42
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
43
|
+
spec.add_development_dependency "rspec", "~> 3.0"
|
44
|
+
spec.add_development_dependency "rspec-rails"
|
45
|
+
spec.add_development_dependency "simplecov"
|
46
|
+
spec.add_development_dependency "simplecov-rcov"
|
47
|
+
spec.add_development_dependency "vcr"
|
48
|
+
spec.add_development_dependency "webmock"
|
49
|
+
end
|
50
|
+
|
51
|
+
# rubocop:enable BlockLength
|
metadata
ADDED
@@ -0,0 +1,271 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: yext-api
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- CardTapp
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2018-01-24 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: rails
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 5.1.2
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 5.1.2
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: spyke
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '5'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '5'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: bundler
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '1.16'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '1.16'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: cornucopia
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: hashie
|
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: rake
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - "~>"
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '10.0'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - "~>"
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '10.0'
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: rspec
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - "~>"
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '3.0'
|
104
|
+
type: :development
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - "~>"
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '3.0'
|
111
|
+
- !ruby/object:Gem::Dependency
|
112
|
+
name: rspec-rails
|
113
|
+
requirement: !ruby/object:Gem::Requirement
|
114
|
+
requirements:
|
115
|
+
- - ">="
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
version: '0'
|
118
|
+
type: :development
|
119
|
+
prerelease: false
|
120
|
+
version_requirements: !ruby/object:Gem::Requirement
|
121
|
+
requirements:
|
122
|
+
- - ">="
|
123
|
+
- !ruby/object:Gem::Version
|
124
|
+
version: '0'
|
125
|
+
- !ruby/object:Gem::Dependency
|
126
|
+
name: simplecov
|
127
|
+
requirement: !ruby/object:Gem::Requirement
|
128
|
+
requirements:
|
129
|
+
- - ">="
|
130
|
+
- !ruby/object:Gem::Version
|
131
|
+
version: '0'
|
132
|
+
type: :development
|
133
|
+
prerelease: false
|
134
|
+
version_requirements: !ruby/object:Gem::Requirement
|
135
|
+
requirements:
|
136
|
+
- - ">="
|
137
|
+
- !ruby/object:Gem::Version
|
138
|
+
version: '0'
|
139
|
+
- !ruby/object:Gem::Dependency
|
140
|
+
name: simplecov-rcov
|
141
|
+
requirement: !ruby/object:Gem::Requirement
|
142
|
+
requirements:
|
143
|
+
- - ">="
|
144
|
+
- !ruby/object:Gem::Version
|
145
|
+
version: '0'
|
146
|
+
type: :development
|
147
|
+
prerelease: false
|
148
|
+
version_requirements: !ruby/object:Gem::Requirement
|
149
|
+
requirements:
|
150
|
+
- - ">="
|
151
|
+
- !ruby/object:Gem::Version
|
152
|
+
version: '0'
|
153
|
+
- !ruby/object:Gem::Dependency
|
154
|
+
name: vcr
|
155
|
+
requirement: !ruby/object:Gem::Requirement
|
156
|
+
requirements:
|
157
|
+
- - ">="
|
158
|
+
- !ruby/object:Gem::Version
|
159
|
+
version: '0'
|
160
|
+
type: :development
|
161
|
+
prerelease: false
|
162
|
+
version_requirements: !ruby/object:Gem::Requirement
|
163
|
+
requirements:
|
164
|
+
- - ">="
|
165
|
+
- !ruby/object:Gem::Version
|
166
|
+
version: '0'
|
167
|
+
- !ruby/object:Gem::Dependency
|
168
|
+
name: webmock
|
169
|
+
requirement: !ruby/object:Gem::Requirement
|
170
|
+
requirements:
|
171
|
+
- - ">="
|
172
|
+
- !ruby/object:Gem::Version
|
173
|
+
version: '0'
|
174
|
+
type: :development
|
175
|
+
prerelease: false
|
176
|
+
version_requirements: !ruby/object:Gem::Requirement
|
177
|
+
requirements:
|
178
|
+
- - ">="
|
179
|
+
- !ruby/object:Gem::Version
|
180
|
+
version: '0'
|
181
|
+
description: A straightforward simple interface with the Yext API v2.
|
182
|
+
email:
|
183
|
+
- dustin@cardtapp.com
|
184
|
+
executables: []
|
185
|
+
extensions: []
|
186
|
+
extra_rdoc_files: []
|
187
|
+
files:
|
188
|
+
- ".gitignore"
|
189
|
+
- ".rspec"
|
190
|
+
- ".rubocop.yml"
|
191
|
+
- ".ruby-version"
|
192
|
+
- ".travis.yml"
|
193
|
+
- CODE_OF_CONDUCT.md
|
194
|
+
- Gemfile
|
195
|
+
- Gemfile.lock
|
196
|
+
- LICENSE.txt
|
197
|
+
- README.md
|
198
|
+
- Rakefile
|
199
|
+
- app/assets/config/yext_api_manifest.js
|
200
|
+
- app/assets/images/yext/api/.keep
|
201
|
+
- app/assets/javascripts/yext/api/application.js
|
202
|
+
- app/assets/stylesheets/yext/api/application.css
|
203
|
+
- app/controllers/yext/api/application_controller.rb
|
204
|
+
- app/docs/notes.txt
|
205
|
+
- app/helpers/yext/api/application_helper.rb
|
206
|
+
- app/jobs/yext/api/application_job.rb
|
207
|
+
- app/mailers/yext/api/application_mailer.rb
|
208
|
+
- app/models/yext/api/application_record.rb
|
209
|
+
- app/views/layouts/yext/api/application.html.erb
|
210
|
+
- bin/console
|
211
|
+
- bin/rails
|
212
|
+
- bin/setup
|
213
|
+
- config/initializers/spyke.rb
|
214
|
+
- config/routes.rb
|
215
|
+
- lib/config/api.yml
|
216
|
+
- lib/tasks/yext/api_tasks.rake
|
217
|
+
- lib/yext/api.rb
|
218
|
+
- lib/yext/api/administrative_api.rb
|
219
|
+
- lib/yext/api/administrative_api/account.rb
|
220
|
+
- lib/yext/api/administrative_api/add_request.rb
|
221
|
+
- lib/yext/api/administrative_api/service.rb
|
222
|
+
- lib/yext/api/concerns/account_child.rb
|
223
|
+
- lib/yext/api/concerns/account_relations.rb
|
224
|
+
- lib/yext/api/concerns/api_finder.rb
|
225
|
+
- lib/yext/api/concerns/default_scopes.rb
|
226
|
+
- lib/yext/api/concerns/enum_all.rb
|
227
|
+
- lib/yext/api/concerns/faraday_connection.rb
|
228
|
+
- lib/yext/api/concerns/rate_limits.rb
|
229
|
+
- lib/yext/api/engine.rb
|
230
|
+
- lib/yext/api/enumerations/validation.rb
|
231
|
+
- lib/yext/api/knowledge_api.rb
|
232
|
+
- lib/yext/api/knowledge_api/account_settings/account.rb
|
233
|
+
- lib/yext/api/knowledge_api/health_check/health.rb
|
234
|
+
- lib/yext/api/knowledge_api/knowledge_manager/category.rb
|
235
|
+
- lib/yext/api/knowledge_api/knowledge_manager/location.rb
|
236
|
+
- lib/yext/api/live_api.rb
|
237
|
+
- lib/yext/api/live_api/location.rb
|
238
|
+
- lib/yext/api/utils/api_base.rb
|
239
|
+
- lib/yext/api/utils/api_rate_limits.rb
|
240
|
+
- lib/yext/api/utils/configuration.rb
|
241
|
+
- lib/yext/api/utils/default_parameters.rb
|
242
|
+
- lib/yext/api/utils/response_parser.rb
|
243
|
+
- lib/yext/api/version.rb
|
244
|
+
- lib/yext/include_rails.rb
|
245
|
+
- yext-api.gemspec
|
246
|
+
homepage: https://github.com/CardTapp/yext-api
|
247
|
+
licenses:
|
248
|
+
- MIT
|
249
|
+
metadata:
|
250
|
+
allowed_push_host: https://rubygems.org
|
251
|
+
post_install_message:
|
252
|
+
rdoc_options: []
|
253
|
+
require_paths:
|
254
|
+
- lib
|
255
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
256
|
+
requirements:
|
257
|
+
- - ">="
|
258
|
+
- !ruby/object:Gem::Version
|
259
|
+
version: '0'
|
260
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
261
|
+
requirements:
|
262
|
+
- - ">="
|
263
|
+
- !ruby/object:Gem::Version
|
264
|
+
version: '0'
|
265
|
+
requirements: []
|
266
|
+
rubyforge_project:
|
267
|
+
rubygems_version: 2.5.1
|
268
|
+
signing_key:
|
269
|
+
specification_version: 4
|
270
|
+
summary: An interface gem to the Yext API.
|
271
|
+
test_files: []
|