octonewsfeed 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/CONTRIBUTING +0 -0
- data/Gemfile +8 -0
- data/LICENSE +202 -0
- data/MAINTAINERS +0 -0
- data/NOTICE +8 -0
- data/README.md +3 -0
- data/lib/octonewsfeed.rb +8 -0
- data/lib/octonewsfeed/feed.rb +76 -0
- data/lib/octonewsfeed/news.rb +11 -0
- data/lib/octonewsfeed/version.rb +5 -0
- data/lib/octonewsfeed/weaver.rb +84 -0
- data/lib/octonewsfeed/webservice.rb +64 -0
- data/spec/spec_helper.rb +103 -0
- metadata +78 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 8f1389962b82c8a3526f8f035dfcbc3b9593bcd9
|
4
|
+
data.tar.gz: 7a6bb0828c95a5c997fa27880609720d4825d308
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: e7cbcba6202229d8e76b101410359a2c7110c099ff5b750416c4e1694e4a96035dfb7ddd0495df545d5b1d8a43786a6d7aba80be2053a0e54a13d218ee061a79
|
7
|
+
data.tar.gz: d945b7151d909d40b1e843d62e6ecd68bf5e7880aa5d770f6b539dc1485900050e3121b0edd4a15f11ca0b0e93a0473dc6744587a93ef4144324b2e80d587e0d
|
data/CONTRIBUTING
ADDED
File without changes
|
data/Gemfile
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,202 @@
|
|
1
|
+
|
2
|
+
Apache License
|
3
|
+
Version 2.0, January 2004
|
4
|
+
http://www.apache.org/licenses/
|
5
|
+
|
6
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
7
|
+
|
8
|
+
1. Definitions.
|
9
|
+
|
10
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
11
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
12
|
+
|
13
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
14
|
+
the copyright owner that is granting the License.
|
15
|
+
|
16
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
17
|
+
other entities that control, are controlled by, or are under common
|
18
|
+
control with that entity. For the purposes of this definition,
|
19
|
+
"control" means (i) the power, direct or indirect, to cause the
|
20
|
+
direction or management of such entity, whether by contract or
|
21
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
22
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
23
|
+
|
24
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
25
|
+
exercising permissions granted by this License.
|
26
|
+
|
27
|
+
"Source" form shall mean the preferred form for making modifications,
|
28
|
+
including but not limited to software source code, documentation
|
29
|
+
source, and configuration files.
|
30
|
+
|
31
|
+
"Object" form shall mean any form resulting from mechanical
|
32
|
+
transformation or translation of a Source form, including but
|
33
|
+
not limited to compiled object code, generated documentation,
|
34
|
+
and conversions to other media types.
|
35
|
+
|
36
|
+
"Work" shall mean the work of authorship, whether in Source or
|
37
|
+
Object form, made available under the License, as indicated by a
|
38
|
+
copyright notice that is included in or attached to the work
|
39
|
+
(an example is provided in the Appendix below).
|
40
|
+
|
41
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
42
|
+
form, that is based on (or derived from) the Work and for which the
|
43
|
+
editorial revisions, annotations, elaborations, or other modifications
|
44
|
+
represent, as a whole, an original work of authorship. For the purposes
|
45
|
+
of this License, Derivative Works shall not include works that remain
|
46
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
47
|
+
the Work and Derivative Works thereof.
|
48
|
+
|
49
|
+
"Contribution" shall mean any work of authorship, including
|
50
|
+
the original version of the Work and any modifications or additions
|
51
|
+
to that Work or Derivative Works thereof, that is intentionally
|
52
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
53
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
54
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
55
|
+
means any form of electronic, verbal, or written communication sent
|
56
|
+
to the Licensor or its representatives, including but not limited to
|
57
|
+
communication on electronic mailing lists, source code control systems,
|
58
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
59
|
+
Licensor for the purpose of discussing and improving the Work, but
|
60
|
+
excluding communication that is conspicuously marked or otherwise
|
61
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
62
|
+
|
63
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
64
|
+
on behalf of whom a Contribution has been received by Licensor and
|
65
|
+
subsequently incorporated within the Work.
|
66
|
+
|
67
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
68
|
+
this License, each Contributor hereby grants to You a perpetual,
|
69
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
70
|
+
copyright license to reproduce, prepare Derivative Works of,
|
71
|
+
publicly display, publicly perform, sublicense, and distribute the
|
72
|
+
Work and such Derivative Works in Source or Object form.
|
73
|
+
|
74
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
75
|
+
this License, each Contributor hereby grants to You a perpetual,
|
76
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
77
|
+
(except as stated in this section) patent license to make, have made,
|
78
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
79
|
+
where such license applies only to those patent claims licensable
|
80
|
+
by such Contributor that are necessarily infringed by their
|
81
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
82
|
+
with the Work to which such Contribution(s) was submitted. If You
|
83
|
+
institute patent litigation against any entity (including a
|
84
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
85
|
+
or a Contribution incorporated within the Work constitutes direct
|
86
|
+
or contributory patent infringement, then any patent licenses
|
87
|
+
granted to You under this License for that Work shall terminate
|
88
|
+
as of the date such litigation is filed.
|
89
|
+
|
90
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
91
|
+
Work or Derivative Works thereof in any medium, with or without
|
92
|
+
modifications, and in Source or Object form, provided that You
|
93
|
+
meet the following conditions:
|
94
|
+
|
95
|
+
(a) You must give any other recipients of the Work or
|
96
|
+
Derivative Works a copy of this License; and
|
97
|
+
|
98
|
+
(b) You must cause any modified files to carry prominent notices
|
99
|
+
stating that You changed the files; and
|
100
|
+
|
101
|
+
(c) You must retain, in the Source form of any Derivative Works
|
102
|
+
that You distribute, all copyright, patent, trademark, and
|
103
|
+
attribution notices from the Source form of the Work,
|
104
|
+
excluding those notices that do not pertain to any part of
|
105
|
+
the Derivative Works; and
|
106
|
+
|
107
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
108
|
+
distribution, then any Derivative Works that You distribute must
|
109
|
+
include a readable copy of the attribution notices contained
|
110
|
+
within such NOTICE file, excluding those notices that do not
|
111
|
+
pertain to any part of the Derivative Works, in at least one
|
112
|
+
of the following places: within a NOTICE text file distributed
|
113
|
+
as part of the Derivative Works; within the Source form or
|
114
|
+
documentation, if provided along with the Derivative Works; or,
|
115
|
+
within a display generated by the Derivative Works, if and
|
116
|
+
wherever such third-party notices normally appear. The contents
|
117
|
+
of the NOTICE file are for informational purposes only and
|
118
|
+
do not modify the License. You may add Your own attribution
|
119
|
+
notices within Derivative Works that You distribute, alongside
|
120
|
+
or as an addendum to the NOTICE text from the Work, provided
|
121
|
+
that such additional attribution notices cannot be construed
|
122
|
+
as modifying the License.
|
123
|
+
|
124
|
+
You may add Your own copyright statement to Your modifications and
|
125
|
+
may provide additional or different license terms and conditions
|
126
|
+
for use, reproduction, or distribution of Your modifications, or
|
127
|
+
for any such Derivative Works as a whole, provided Your use,
|
128
|
+
reproduction, and distribution of the Work otherwise complies with
|
129
|
+
the conditions stated in this License.
|
130
|
+
|
131
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
132
|
+
any Contribution intentionally submitted for inclusion in the Work
|
133
|
+
by You to the Licensor shall be under the terms and conditions of
|
134
|
+
this License, without any additional terms or conditions.
|
135
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
136
|
+
the terms of any separate license agreement you may have executed
|
137
|
+
with Licensor regarding such Contributions.
|
138
|
+
|
139
|
+
6. Trademarks. This License does not grant permission to use the trade
|
140
|
+
names, trademarks, service marks, or product names of the Licensor,
|
141
|
+
except as required for reasonable and customary use in describing the
|
142
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
143
|
+
|
144
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
145
|
+
agreed to in writing, Licensor provides the Work (and each
|
146
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
147
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
148
|
+
implied, including, without limitation, any warranties or conditions
|
149
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
150
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
151
|
+
appropriateness of using or redistributing the Work and assume any
|
152
|
+
risks associated with Your exercise of permissions under this License.
|
153
|
+
|
154
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
155
|
+
whether in tort (including negligence), contract, or otherwise,
|
156
|
+
unless required by applicable law (such as deliberate and grossly
|
157
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
158
|
+
liable to You for damages, including any direct, indirect, special,
|
159
|
+
incidental, or consequential damages of any character arising as a
|
160
|
+
result of this License or out of the use or inability to use the
|
161
|
+
Work (including but not limited to damages for loss of goodwill,
|
162
|
+
work stoppage, computer failure or malfunction, or any and all
|
163
|
+
other commercial damages or losses), even if such Contributor
|
164
|
+
has been advised of the possibility of such damages.
|
165
|
+
|
166
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
167
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
168
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
169
|
+
or other liability obligations and/or rights consistent with this
|
170
|
+
License. However, in accepting such obligations, You may act only
|
171
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
172
|
+
of any other Contributor, and only if You agree to indemnify,
|
173
|
+
defend, and hold each Contributor harmless for any liability
|
174
|
+
incurred by, or claims asserted against, such Contributor by reason
|
175
|
+
of your accepting any such warranty or additional liability.
|
176
|
+
|
177
|
+
END OF TERMS AND CONDITIONS
|
178
|
+
|
179
|
+
APPENDIX: How to apply the Apache License to your work.
|
180
|
+
|
181
|
+
To apply the Apache License to your work, attach the following
|
182
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
183
|
+
replaced with your own identifying information. (Don't include
|
184
|
+
the brackets!) The text should be enclosed in the appropriate
|
185
|
+
comment syntax for the file format. We also recommend that a
|
186
|
+
file or class name and description of purpose be included on the
|
187
|
+
same "printed page" as the copyright notice for easier
|
188
|
+
identification within third-party archives.
|
189
|
+
|
190
|
+
Copyright [yyyy] [name of copyright owner]
|
191
|
+
|
192
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
193
|
+
you may not use this file except in compliance with the License.
|
194
|
+
You may obtain a copy of the License at
|
195
|
+
|
196
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
197
|
+
|
198
|
+
Unless required by applicable law or agreed to in writing, software
|
199
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
200
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
201
|
+
See the License for the specific language governing permissions and
|
202
|
+
limitations under the License.
|
data/MAINTAINERS
ADDED
File without changes
|
data/NOTICE
ADDED
@@ -0,0 +1,8 @@
|
|
1
|
+
Octo.ai, (C) 2015,2016 Aurora Borealis Technologies Pvt. Ltd.
|
2
|
+
|
3
|
+
This product includes software developed at Aurora Borealis Technologies Pvt. Ltd (https://octo.ai/).
|
4
|
+
|
5
|
+
The Octoai project contains unmodified/modified subcomponents too with
|
6
|
+
separate copyright notices and license terms. Your use of the source
|
7
|
+
code for these subcomponents is subject to the terms and conditions
|
8
|
+
of the following licenses.
|
data/README.md
ADDED
data/lib/octonewsfeed.rb
ADDED
@@ -0,0 +1,76 @@
|
|
1
|
+
require 'octorecommender'
|
2
|
+
require 'octonewsfeed/weaver'
|
3
|
+
|
4
|
+
module Octo
|
5
|
+
module NewsFeed
|
6
|
+
|
7
|
+
module Feed
|
8
|
+
include Octo::NewsFeed::Weaver
|
9
|
+
|
10
|
+
# Generate the newsfeed for a user. Optionally,
|
11
|
+
# specify a time so that things relevant at that time would show
|
12
|
+
# @param [Octo::User] user The user for whom feed is to be generated
|
13
|
+
# @param [Hash] opts The options to use for for generating feed
|
14
|
+
def feed_for(user, opts = {})
|
15
|
+
feed_products = {
|
16
|
+
recommended: recommender.recommended_products(user),
|
17
|
+
trending: trending_prods(user.enterprise),
|
18
|
+
similar: similar_prods_user(user)
|
19
|
+
}
|
20
|
+
weave(feed_products)
|
21
|
+
end
|
22
|
+
|
23
|
+
private
|
24
|
+
|
25
|
+
# Generate the recommender instance
|
26
|
+
# @return [Octo::Recommender]
|
27
|
+
def recommender
|
28
|
+
@recommender = Octo::Recommender.new unless @recommender
|
29
|
+
@recommender
|
30
|
+
end
|
31
|
+
|
32
|
+
# Gets the set of trending products for the enterprise. This is as per
|
33
|
+
# custom logic of how many trending products and of what type do we
|
34
|
+
# want to show to the user in his newsfeed.
|
35
|
+
# @param [Octo::Enterprise] enterprise The enterprise for whom trendings
|
36
|
+
# to be calculated
|
37
|
+
# @return [Array<Octo::Product>] An array of products
|
38
|
+
def trending_prods(enterprise)
|
39
|
+
eid = enterprise.id
|
40
|
+
trending_now = Octo::ProductTrend.get_trending eid, Octo::Counter::TYPE_MINUTE, limit: 10
|
41
|
+
trending_past = Octo::ProductTrend.get_trending eid, Octo::Counter::TYPE_HOUR, limit: 10
|
42
|
+
trending_now.concat trending_past
|
43
|
+
end
|
44
|
+
|
45
|
+
# Finds the products similar to the ones that the user has seen before.
|
46
|
+
# @param [Octo::User] user The user for whom similar products have to be
|
47
|
+
# found
|
48
|
+
# @return [Array<Octo::Product>] An array of products
|
49
|
+
def similar_prods_user(user, opts={})
|
50
|
+
args = {
|
51
|
+
enterprise_id: user.enterprise.id,
|
52
|
+
userid: user.id
|
53
|
+
}
|
54
|
+
last_ppvs = Octo::ProductPageView.where(args).limit(opts.fetch(:limit, 10))
|
55
|
+
last_seen_products = last_ppvs.collect do |ppv|
|
56
|
+
Octo::Product.get_cached({ enterprise_id: user.enterprise.id,
|
57
|
+
id: ppv.product_id})
|
58
|
+
end
|
59
|
+
similar_prods last_seen_products
|
60
|
+
end
|
61
|
+
|
62
|
+
# Get similar products for a set of products.
|
63
|
+
# @param [Array<Octo::Product>] products An array of products for whom
|
64
|
+
# similarities have to be found
|
65
|
+
# @return [Hash<Octo::Product => Array<Octo::Product>] Hash containing similar
|
66
|
+
# products array as value for product as key
|
67
|
+
def similar_prods(products, opts={})
|
68
|
+
products.inject({}) do |r,e|
|
69
|
+
r[e] = e.similarities(opts)
|
70
|
+
r
|
71
|
+
end
|
72
|
+
end
|
73
|
+
|
74
|
+
end
|
75
|
+
end
|
76
|
+
end
|
@@ -0,0 +1,84 @@
|
|
1
|
+
module Octo
|
2
|
+
module NewsFeed
|
3
|
+
|
4
|
+
module Weaver
|
5
|
+
|
6
|
+
# Weaves up all the various things to be shown
|
7
|
+
# in the newsfeed
|
8
|
+
# @param [Hash{Symbol => Array}] args The products hash
|
9
|
+
# to be used for weaving.
|
10
|
+
# This hash should contain a key which symbolises/groups types
|
11
|
+
# of products - trending, recommended, promoted etc.
|
12
|
+
# @param [Hash] opts The options used for weaving
|
13
|
+
# @return [Array] Weaved array of items
|
14
|
+
def weave(items, opts={})
|
15
|
+
order = opts.fetch(:order, weaving_order)
|
16
|
+
|
17
|
+
items_count = items.values.flatten.length
|
18
|
+
order_length = order[:tag_items_count].length
|
19
|
+
|
20
|
+
tag_length = order[:tag_order].length
|
21
|
+
|
22
|
+
loop_count = items_count/order_length + items_count%order_length
|
23
|
+
|
24
|
+
_feed = []
|
25
|
+
|
26
|
+
loop_count.times do |i|
|
27
|
+
init_index = i*tag_length
|
28
|
+
if init_index >= order_length
|
29
|
+
init_index = order_length - tag_length
|
30
|
+
end
|
31
|
+
end_index = init_index + tag_length
|
32
|
+
count_of_tags = order[:tag_items_count].slice(init_index...end_index)
|
33
|
+
order[:tag_order].each_with_index do |tag, index|
|
34
|
+
_feed.concat(items[tag].take(count_of_tags[index]))
|
35
|
+
end
|
36
|
+
end
|
37
|
+
_feed
|
38
|
+
end
|
39
|
+
|
40
|
+
|
41
|
+
# Returns a hash which contains key the data that decides how the items
|
42
|
+
# would be weaved.
|
43
|
+
#
|
44
|
+
# It is a hash containing a key :tag_order that decides the priority
|
45
|
+
# of item groups (like trending, recommended, promoted). This info
|
46
|
+
# is used in understanding the data in other key.
|
47
|
+
#
|
48
|
+
# The other key :tag_items_count contains an array of numbers. These
|
49
|
+
# numbers signify the count of each item group that would be used
|
50
|
+
# to generate the news feed.
|
51
|
+
#
|
52
|
+
# The last pattern represented by :tag_items_count would keep on
|
53
|
+
# repeating itself if :tag_items_count's length is smaller than
|
54
|
+
# the length of items
|
55
|
+
#
|
56
|
+
# Example:
|
57
|
+
#
|
58
|
+
# Suppose the items that would constitute the feed are
|
59
|
+
# { trending: Array(10..20),
|
60
|
+
# recommended: Array(30..40),
|
61
|
+
# promoted: Array(50..60)
|
62
|
+
# }
|
63
|
+
#
|
64
|
+
# and the corresponding weaving order is as follows
|
65
|
+
# { tag_order: [:trending, :promoted, :recommended],
|
66
|
+
# tag_items_count: [2,3,1, 1,2,1, 3,2,1, 1,0,2, 2,4,0, 1,2,1]
|
67
|
+
# }
|
68
|
+
#
|
69
|
+
# Then the generated feed would like like
|
70
|
+
#
|
71
|
+
# [10, 11, 30, 31, 32, 50, 10, 30, 31, 50, 10, 11, 12, 30, 31, 50,
|
72
|
+
# 10, 50, 51, 10, 11, 30, 31, 32, 33, 10, 30, 31, 50, 10, 30, 31,
|
73
|
+
# 50, 10, 30, 31, 50, 10, 30, 31, 50, 10, 30, 31, 50, 10, 30, 31,...
|
74
|
+
#
|
75
|
+
# @return [Hash] data structure which weaves
|
76
|
+
def weaving_order
|
77
|
+
{
|
78
|
+
tag_order: [:trending, :recommended, :similar],
|
79
|
+
tag_items_count: [2,3,1, 1,2,1, 3,2,1, 1,0,2, 2,4,0, 1,2,1]
|
80
|
+
}
|
81
|
+
end
|
82
|
+
end
|
83
|
+
end
|
84
|
+
end
|
@@ -0,0 +1,64 @@
|
|
1
|
+
require 'sinatra/base'
|
2
|
+
require 'octocore/helpers/sinatra_helper'
|
3
|
+
|
4
|
+
module Octo
|
5
|
+
module NewsFeed
|
6
|
+
|
7
|
+
module WebServiceHelper
|
8
|
+
|
9
|
+
# Get newsfeed for a user
|
10
|
+
# @param [String] enterprise_id The enterpriseid of enterprise
|
11
|
+
# @param [Fixnum] user_id The user id of the user
|
12
|
+
# @param [Hash] opts The options hash.
|
13
|
+
# @option opts [Fixnum] :page The page of newsfeed to fetch
|
14
|
+
# @option opts [Time] :ts The time at which newsfeed should be
|
15
|
+
# generated
|
16
|
+
# @return [JSON] A json value representing the newsfeed or the
|
17
|
+
# error response
|
18
|
+
def get_newsfeed_for(enterprise_id, user_id, opts = {})
|
19
|
+
args = {
|
20
|
+
enterprise_id: enterprise_id,
|
21
|
+
user_id: user_id
|
22
|
+
}
|
23
|
+
user = Octo::User.where(args).first
|
24
|
+
if user
|
25
|
+
Octo::NewsFeed::News.feed_for(user, opts).to_json
|
26
|
+
else
|
27
|
+
{status: 404, message: 'User not found'}.to_json
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
# WebService class for Newsfeed
|
33
|
+
class WebService < ::Sinatra::Base
|
34
|
+
extend Octo::Sinatra::Helper
|
35
|
+
extend Octo::NewsFeed::WebServiceHelper
|
36
|
+
|
37
|
+
configure do
|
38
|
+
logger = Octo::ApiLogger.logger
|
39
|
+
set logger: logger
|
40
|
+
end
|
41
|
+
|
42
|
+
# Define an enterprise facing endpoint.This endpoint should be
|
43
|
+
# front faced by kong, as it finds enterprise details implicitly
|
44
|
+
# from the HTTP headers set by kong
|
45
|
+
get '/feed/:user_id/:page?' do
|
46
|
+
content_type :json
|
47
|
+
params.deep_symbolize_keys!
|
48
|
+
eid = enterprise_details[:custom_id]
|
49
|
+
opts = { page: params.fetch(:page, 1)}
|
50
|
+
get_newsfeed_for(eid, params[:user_id], opts)
|
51
|
+
end
|
52
|
+
|
53
|
+
# Define a route for internal purposes. This may be the one
|
54
|
+
# that is not behind kong and needs to be told the
|
55
|
+
# enterprise_id
|
56
|
+
get '/:enterprise_id/feed/:user_id/:page?' do
|
57
|
+
content_type :json
|
58
|
+
params.deep_symbolize_keys!
|
59
|
+
opts = { page: params.fetch(:page, 1)}
|
60
|
+
get_newsfeed_for(params[:enterprise_id], params[:user_id], opts)
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,103 @@
|
|
1
|
+
# This file was generated by the `rspec --init` command. Conventionally, all
|
2
|
+
# specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
|
3
|
+
# The generated `.rspec` file contains `--require spec_helper` which will cause
|
4
|
+
# this file to always be loaded, without a need to explicitly require it in any
|
5
|
+
# files.
|
6
|
+
#
|
7
|
+
# Given that it is always loaded, you are encouraged to keep this file as
|
8
|
+
# light-weight as possible. Requiring heavyweight dependencies from this file
|
9
|
+
# will add to the boot time of your test suite on EVERY test run, even for an
|
10
|
+
# individual file that may not need all of that loaded. Instead, consider making
|
11
|
+
# a separate helper file that requires the additional dependencies and performs
|
12
|
+
# the additional setup, and require it from the spec files that actually need
|
13
|
+
# it.
|
14
|
+
#
|
15
|
+
# The `.rspec` file also contains a few flags that are not defaults but that
|
16
|
+
# users commonly want.
|
17
|
+
#
|
18
|
+
# See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
|
19
|
+
RSpec.configure do |config|
|
20
|
+
# rspec-expectations config goes here. You can use an alternate
|
21
|
+
# assertion/expectation library such as wrong or the stdlib/minitest
|
22
|
+
# assertions if you prefer.
|
23
|
+
config.expect_with :rspec do |expectations|
|
24
|
+
# This option will default to `true` in RSpec 4. It makes the `description`
|
25
|
+
# and `failure_message` of custom matchers include text for helper methods
|
26
|
+
# defined using `chain`, e.g.:
|
27
|
+
# be_bigger_than(2).and_smaller_than(4).description
|
28
|
+
# # => "be bigger than 2 and smaller than 4"
|
29
|
+
# ...rather than:
|
30
|
+
# # => "be bigger than 2"
|
31
|
+
expectations.include_chain_clauses_in_custom_matcher_descriptions = true
|
32
|
+
end
|
33
|
+
|
34
|
+
# rspec-mocks config goes here. You can use an alternate test double
|
35
|
+
# library (such as bogus or mocha) by changing the `mock_with` option here.
|
36
|
+
config.mock_with :rspec do |mocks|
|
37
|
+
# Prevents you from mocking or stubbing a method that does not exist on
|
38
|
+
# a real object. This is generally recommended, and will default to
|
39
|
+
# `true` in RSpec 4.
|
40
|
+
mocks.verify_partial_doubles = true
|
41
|
+
end
|
42
|
+
|
43
|
+
# This option will default to `:apply_to_host_groups` in RSpec 4 (and will
|
44
|
+
# have no way to turn it off -- the option exists only for backwards
|
45
|
+
# compatibility in RSpec 3). It causes shared context metadata to be
|
46
|
+
# inherited by the metadata hash of host groups and examples, rather than
|
47
|
+
# triggering implicit auto-inclusion in groups with matching metadata.
|
48
|
+
config.shared_context_metadata_behavior = :apply_to_host_groups
|
49
|
+
|
50
|
+
# The settings below are suggested to provide a good initial experience
|
51
|
+
# with RSpec, but feel free to customize to your heart's content.
|
52
|
+
=begin
|
53
|
+
# This allows you to limit a spec run to individual examples or groups
|
54
|
+
# you care about by tagging them with `:focus` metadata. When nothing
|
55
|
+
# is tagged with `:focus`, all examples get run. RSpec also provides
|
56
|
+
# aliases for `it`, `describe`, and `context` that include `:focus`
|
57
|
+
# metadata: `fit`, `fdescribe` and `fcontext`, respectively.
|
58
|
+
config.filter_run_when_matching :focus
|
59
|
+
|
60
|
+
# Allows RSpec to persist some state between runs in order to support
|
61
|
+
# the `--only-failures` and `--next-failure` CLI options. We recommend
|
62
|
+
# you configure your source control system to ignore this file.
|
63
|
+
config.example_status_persistence_file_path = "spec/examples.txt"
|
64
|
+
|
65
|
+
# Limits the available syntax to the non-monkey patched syntax that is
|
66
|
+
# recommended. For more details, see:
|
67
|
+
# - http://rspec.info/blog/2012/06/rspecs-new-expectation-syntax/
|
68
|
+
# - http://www.teaisaweso.me/blog/2013/05/27/rspecs-new-message-expectation-syntax/
|
69
|
+
# - http://rspec.info/blog/2014/05/notable-changes-in-rspec-3/#zero-monkey-patching-mode
|
70
|
+
config.disable_monkey_patching!
|
71
|
+
|
72
|
+
# This setting enables warnings. It's recommended, but in some cases may
|
73
|
+
# be too noisy due to issues in dependencies.
|
74
|
+
config.warnings = true
|
75
|
+
|
76
|
+
# Many RSpec users commonly either run the entire suite or an individual
|
77
|
+
# file, and it's useful to allow more verbose output when running an
|
78
|
+
# individual spec file.
|
79
|
+
if config.files_to_run.one?
|
80
|
+
# Use the documentation formatter for detailed output,
|
81
|
+
# unless a formatter has already been configured
|
82
|
+
# (e.g. via a command-line flag).
|
83
|
+
config.default_formatter = 'doc'
|
84
|
+
end
|
85
|
+
|
86
|
+
# Print the 10 slowest examples and example groups at the
|
87
|
+
# end of the spec run, to help surface which specs are running
|
88
|
+
# particularly slow.
|
89
|
+
config.profile_examples = 10
|
90
|
+
|
91
|
+
# Run specs in random order to surface order dependencies. If you find an
|
92
|
+
# order dependency and want to debug it, you can fix the order by providing
|
93
|
+
# the seed, which is printed after each run.
|
94
|
+
# --seed 1234
|
95
|
+
config.order = :random
|
96
|
+
|
97
|
+
# Seed global randomization in this process using the `--seed` CLI option.
|
98
|
+
# Setting this allows you to use `--seed` to deterministically reproduce
|
99
|
+
# test failures related to randomization by passing the same `--seed` value
|
100
|
+
# as the one that triggered the failure.
|
101
|
+
Kernel.srand config.seed
|
102
|
+
=end
|
103
|
+
end
|
metadata
ADDED
@@ -0,0 +1,78 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: octonewsfeed
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- PranavPrakash
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2016-03-19 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: octorecommender
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 0.0.1
|
20
|
+
- - ">="
|
21
|
+
- !ruby/object:Gem::Version
|
22
|
+
version: 0.0.1
|
23
|
+
type: :runtime
|
24
|
+
prerelease: false
|
25
|
+
version_requirements: !ruby/object:Gem::Requirement
|
26
|
+
requirements:
|
27
|
+
- - "~>"
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: 0.0.1
|
30
|
+
- - ">="
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: 0.0.1
|
33
|
+
description: Components needed for a newsfeed
|
34
|
+
email: pp@octo.ai
|
35
|
+
executables: []
|
36
|
+
extensions: []
|
37
|
+
extra_rdoc_files:
|
38
|
+
- README.md
|
39
|
+
files:
|
40
|
+
- CONTRIBUTING
|
41
|
+
- Gemfile
|
42
|
+
- LICENSE
|
43
|
+
- MAINTAINERS
|
44
|
+
- NOTICE
|
45
|
+
- README.md
|
46
|
+
- lib/octonewsfeed.rb
|
47
|
+
- lib/octonewsfeed/feed.rb
|
48
|
+
- lib/octonewsfeed/news.rb
|
49
|
+
- lib/octonewsfeed/version.rb
|
50
|
+
- lib/octonewsfeed/weaver.rb
|
51
|
+
- lib/octonewsfeed/webservice.rb
|
52
|
+
- spec/spec_helper.rb
|
53
|
+
homepage: http://phab.octo.ai/diffusion/GEMS/
|
54
|
+
licenses:
|
55
|
+
- MIT
|
56
|
+
metadata: {}
|
57
|
+
post_install_message:
|
58
|
+
rdoc_options: []
|
59
|
+
require_paths:
|
60
|
+
- lib
|
61
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
62
|
+
requirements:
|
63
|
+
- - ">="
|
64
|
+
- !ruby/object:Gem::Version
|
65
|
+
version: '2.0'
|
66
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
67
|
+
requirements:
|
68
|
+
- - ">="
|
69
|
+
- !ruby/object:Gem::Version
|
70
|
+
version: '0'
|
71
|
+
requirements: []
|
72
|
+
rubyforge_project:
|
73
|
+
rubygems_version: 2.4.6
|
74
|
+
signing_key:
|
75
|
+
specification_version: 4
|
76
|
+
summary: All things newsfeed
|
77
|
+
test_files: []
|
78
|
+
has_rdoc: true
|