Class: API
- Inherits:
-
Object
show all
- Defined in:
- lib/quintype/api.rb,
lib/quintype/api/tag.rb,
lib/quintype/api/url.rb,
lib/quintype/api/stack.rb,
lib/quintype/api/story.rb,
lib/quintype/api/author.rb,
lib/quintype/api/entity.rb,
lib/quintype/api/story/reading_time.rb
Defined Under Namespace
Classes: Author, Entity, Stack, Story, Tag, URL
Class Method Summary
collapse
-
.author_profile(author_id) ⇒ Object
-
.authors(params) ⇒ Object
-
.bulk_cached(params) ⇒ Object
-
.bulk_post(params) ⇒ Object
-
.bulk_v1_cached(params) ⇒ Object
-
.check_email(email) ⇒ Object
-
.collection(slug, options) ⇒ Object
This is a hack because we can’t migrate entire APIs to use v1 [Varun - 14th December 2016].
-
.comments_and_likes(story_ids) ⇒ Object
-
.config ⇒ Object
-
.conn ⇒ Object
-
.contact_publisher(params) ⇒ Object
-
.entities(params) ⇒ Object
-
.establish_connection(host, conn = Faraday.new(url: host)) ⇒ Object
-
.find_entity(id) ⇒ Object
-
.forgot_password(member) ⇒ Object
-
.get_member_metadata(session_cookie) ⇒ Object
-
.invite_users(emails, from_email, from_name) ⇒ Object
-
.login(provider, data) ⇒ Object
-
.login_member(auth) ⇒ Object
-
.logout ⇒ Object
-
.post_comment(story_content_id, text, parent_comment_id = nil, session_cookie) ⇒ Object
-
.preview_story(public_preview_key) ⇒ Object
-
.related_stories(story_id, section, fields = []) ⇒ Object
-
.reset_password(params) ⇒ Object
-
.save_member_metadata(metadata, session_cookie) ⇒ Object
-
.search(options) ⇒ Object
-
.search_story_collection(name, options) ⇒ Object
-
.sections ⇒ Object
-
.signup_member(member) ⇒ Object
-
.slugify(x) ⇒ Object
-
.stories(params, options = {}) ⇒ Object
-
.story(story_id) ⇒ Object
-
.story_by_slug(slug, params = {}) ⇒ Object
-
.story_collection(options) ⇒ Object
-
.story_collection_by_tag(options) ⇒ Object
-
.sub_entity(entity_id, sub_entity_id) ⇒ Object
-
.subscribe(member, profile, payment) ⇒ Object
-
.tag_by_name(tag_name) ⇒ Object
-
.unsubscribe(options) ⇒ Object
-
.unsubscribe_publisher(params) ⇒ Object
-
.videos ⇒ Object
-
.vote_on_story(data) ⇒ Object
-
.votes_on_story(options = {}) ⇒ Object
Class Method Details
.author_profile(author_id) ⇒ Object
175
176
177
|
# File 'lib/quintype/api.rb', line 175
def author_profile(author_id)
_get("author/#{author_id}")
end
|
.authors(params) ⇒ Object
171
172
173
|
# File 'lib/quintype/api.rb', line 171
def authors(params)
_get("authors", params)
end
|
.bulk_cached(params) ⇒ Object
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
|
# File 'lib/quintype/api.rb', line 27
def bulk_cached(params)
response_body = nil
location = @@bulk_cache.fetch(params) do |params|
response = @@conn.post(@@api_base + "bulk-request", params) do |request|
request.['Content-Type'] = 'application/json'
request.body = params.to_json
end
if response.status == 303 && response.["Location"]
response.["Location"]
elsif response.status == 200 && response.["Content-Location"]
response_body = keywordize(JSON.parse(response.body))
log_info("The faraday adapter is configured to follow redirects by default. Using the Content-Location header")
response.["Content-Location"]
else
raise "Did not recieve a location header, status #{response.status}"
end
end
response_body || _get(location.sub(/^\/api\//, ""))
end
|
.bulk_post(params) ⇒ Object
23
24
25
|
# File 'lib/quintype/api.rb', line 23
def bulk_post(params)
_post("bulk", params)
end
|
.bulk_v1_cached(params) ⇒ Object
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
|
# File 'lib/quintype/api.rb', line 50
def bulk_v1_cached(params)
response_body = nil
location = @@bulk_cache.fetch(params) do |params|
response = @@conn.post("/api/v1/bulk-request", params) do |request|
request.['Content-Type'] = 'application/json'
request.body = params.to_json
end
if response.status == 303 && response.["Location"]
response.["Location"]
elsif response.status == 200 && response.["Content-Location"]
response_body = keywordize(JSON.parse(response.body))
log_info("The faraday adapter is configured to follow redirects by default. Using the Content-Location header")
response.["Content-Location"]
else
raise "Did not recieve a location header, status #{response.status}"
end
end
response_body || _get(location.sub(/^\/api\//, ""))
end
|
.check_email(email) ⇒ Object
203
204
205
|
# File 'lib/quintype/api.rb', line 203
def check_email(email)
_get("member/check", { email: email })
end
|
.collection(slug, options) ⇒ Object
This is a hack because we can’t migrate entire APIs to use v1 [Varun - 14th December 2016]
134
135
136
|
# File 'lib/quintype/api.rb', line 134
def collection(slug, options)
_get("v1/collections/" + slug, options)
end
|
111
112
113
114
115
|
# File 'lib/quintype/api.rb', line 111
def comments_and_likes(story_ids)
if story_ids.present?
_get("comments-and-votes/" + story_ids.join('|'))
end
end
|
.config ⇒ Object
74
75
76
|
# File 'lib/quintype/api.rb', line 74
def config
_get("config")
end
|
.conn ⇒ Object
19
20
21
|
# File 'lib/quintype/api.rb', line 19
def conn
@@conn
end
|
163
164
165
|
# File 'lib/quintype/api.rb', line 163
def contact_publisher(params)
_post("emails/contact", params)
end
|
.entities(params) ⇒ Object
245
246
247
|
# File 'lib/quintype/api.rb', line 245
def entities(params)
_get("v1/entities", params)
end
|
.establish_connection(host, conn = Faraday.new(url: host)) ⇒ Object
12
13
14
15
16
17
|
# File 'lib/quintype/api.rb', line 12
def establish_connection(host, conn = Faraday.new(url: host))
@@host = host
@@api_base = host + '/api/'
@@bulk_cache ||= ActiveSupport::Cache::MemoryStore.new
@@conn = conn
end
|
.find_entity(id) ⇒ Object
249
250
251
|
# File 'lib/quintype/api.rb', line 249
def find_entity(id)
_get("v1/entities/#{id}")
end
|
.forgot_password(member) ⇒ Object
225
226
227
|
# File 'lib/quintype/api.rb', line 225
def forgot_password(member)
_post("member/forgot-password", member)
end
|
199
200
201
|
# File 'lib/quintype/api.rb', line 199
def get_member_metadata(session_cookie)
_get("member/metadata", {}, { auth_token: session_cookie})
end
|
.invite_users(emails, from_email, from_name) ⇒ Object
155
156
157
158
159
160
161
|
# File 'lib/quintype/api.rb', line 155
def invite_users(emails, from_email, from_name)
params = { emails: emails }
params['from-email'] = from_email if from_email.present?
params['from-name'] = from_name if from_name.present?
_post("emails/invite", params)
end
|
.login(provider, data) ⇒ Object
215
216
217
218
219
|
# File 'lib/quintype/api.rb', line 215
def login(provider, data)
user, = ("login/#{provider}", data)
user['auth_token'] = ['X-QT-AUTH']
user['member'].merge(user.except('member'))
end
|
.login_member(auth) ⇒ Object
211
212
213
|
# File 'lib/quintype/api.rb', line 211
def login_member(auth)
_post("member/login", auth)
end
|
.logout ⇒ Object
221
222
223
|
# File 'lib/quintype/api.rb', line 221
def logout
_get("logout")
end
|
146
147
148
149
150
151
152
153
|
# File 'lib/quintype/api.rb', line 146
def (story_content_id, text, =nil, session_cookie)
hash = {
"story-content-id" => story_content_id,
"text" => text
}
hash.merge!("parent-comment-id" => .to_i) if
_post("comment", hash, session_cookie)
end
|
.preview_story(public_preview_key) ⇒ Object
241
242
243
|
# File 'lib/quintype/api.rb', line 241
def preview_story(public_preview_key)
_get("v1/preview/story/#{public_preview_key}")
end
|
98
99
100
101
102
103
104
|
# File 'lib/quintype/api.rb', line 98
def related_stories(story_id, section, fields = [])
_get("related-stories?", {
"story-id" => story_id,
section: section,
fields: make_fields(fields)
})
end
|
.reset_password(params) ⇒ Object
229
230
231
|
# File 'lib/quintype/api.rb', line 229
def reset_password(params)
_post("member/password", params)
end
|
195
196
197
|
# File 'lib/quintype/api.rb', line 195
def save_member_metadata(metadata, session_cookie)
_post("member/metadata", { metadata: metadata }, session_cookie)
end
|
.search(options) ⇒ Object
179
180
181
|
# File 'lib/quintype/api.rb', line 179
def search(options)
_get("search", options)
end
|
.search_story_collection(name, options) ⇒ Object
125
126
127
128
129
130
131
|
# File 'lib/quintype/api.rb', line 125
def search_story_collection(name, options)
_get("story-collection", {
name: name,
type: "search",
fields: "author-name,hero-image-s3-key,hero-image-metadata,hero-image-caption,headline,slug,sections,metadata"
}.merge(options))
end
|
.sections ⇒ Object
78
79
80
|
# File 'lib/quintype/api.rb', line 78
def sections
_get("sections")
end
|
.signup_member(member) ⇒ Object
207
208
209
|
# File 'lib/quintype/api.rb', line 207
def signup_member(member)
_post("member", member)
end
|
.slugify(x) ⇒ Object
86
87
88
|
# File 'lib/quintype/api.rb', line 86
def slugify(x)
_get("slugify/#{x}")
end
|
.stories(params, options = {}) ⇒ Object
106
107
108
109
|
# File 'lib/quintype/api.rb', line 106
def stories(params, options = {})
url = options[:facets] ? "stories-with-facets" : "stories"
_get(url, params)
end
|
.story(story_id) ⇒ Object
82
83
84
|
# File 'lib/quintype/api.rb', line 82
def story(story_id)
_get("stories/#{story_id}")
end
|
.story_by_slug(slug, params = {}) ⇒ Object
94
95
96
|
# File 'lib/quintype/api.rb', line 94
def story_by_slug(slug, params = {})
_get("stories-by-slug", params.merge({ slug: slug }))
end
|
.story_collection(options) ⇒ Object
138
139
140
|
# File 'lib/quintype/api.rb', line 138
def story_collection(options)
_get("story-collection", options)
end
|
.story_collection_by_tag(options) ⇒ Object
142
143
144
|
# File 'lib/quintype/api.rb', line 142
def story_collection_by_tag(options)
_get("story-collection/find-by-tag", options)
end
|
.sub_entity(entity_id, sub_entity_id) ⇒ Object
253
254
255
|
# File 'lib/quintype/api.rb', line 253
def sub_entity(entity_id, sub_entity_id)
_get("v1/entities/#{entity_id}/#{sub_entity_id}")
end
|
.subscribe(member, profile, payment) ⇒ Object
183
184
185
186
187
188
189
|
# File 'lib/quintype/api.rb', line 183
def subscribe(member, profile, payment)
_post("subscribe", {
member: member,
profile: profile,
payment: payment
})
end
|
.tag_by_name(tag_name) ⇒ Object
90
91
92
|
# File 'lib/quintype/api.rb', line 90
def tag_by_name(tag_name)
_get("tag/#{tag_name}")
end
|
.unsubscribe(options) ⇒ Object
191
192
193
|
# File 'lib/quintype/api.rb', line 191
def unsubscribe(options)
_post("unsubscribe", { options: options })
end
|
.unsubscribe_publisher(params) ⇒ Object
167
168
169
|
# File 'lib/quintype/api.rb', line 167
def unsubscribe_publisher(params)
_post("emails/unsubscribe", params)
end
|
.videos ⇒ Object
117
118
119
120
121
122
123
|
# File 'lib/quintype/api.rb', line 117
def videos
_get("stories-by-template", {
template: "video",
limit: 12,
fields: "hero-image-s3-key,hero-image-metadata,hero-image-caption,headline,slug"
})
end
|
.vote_on_story(data) ⇒ Object
233
234
235
|
# File 'lib/quintype/api.rb', line 233
def vote_on_story (data)
_post("stories/#{data[:story_id]}/votes", data)
end
|
.votes_on_story(options = {}) ⇒ Object
237
238
239
|
# File 'lib/quintype/api.rb', line 237
def votes_on_story (options = {})
_get("stories/#{story_id}/votes", options)
end
|