brainspace 0.1.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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 48d471a444baaf087f07b5f36cde0f05ada724bb
4
+ data.tar.gz: c1cfec19537408264943f4793506493cc90fe3aa
5
+ SHA512:
6
+ metadata.gz: c04c7c20015d9b7ff26e3c6d9baecb1221a01681ca0914949ff1d14d456c09abdf6c4b42d256ff14db5ebd40d36480a614945c7726d1ba972fe5aa2340edc772
7
+ data.tar.gz: fd04ab43966cc1acbf5e42c8c0b7349fb1d4c04b26e35709461ffb1e0318835b5b04184d78573b5dbeaa7d1a9f94b4bfb1a4085a3776548e54a68a5b028107ce
data/.gitignore ADDED
@@ -0,0 +1,34 @@
1
+ *.gem
2
+ *.rbc
3
+ /.config
4
+ /coverage/
5
+ /InstalledFiles
6
+ /pkg/
7
+ /spec/reports/
8
+ /test/tmp/
9
+ /test/version_tmp/
10
+ /tmp/
11
+
12
+ ## Specific to RubyMotion:
13
+ .dat*
14
+ .repl_history
15
+ build/
16
+
17
+ ## Documentation cache and generated files:
18
+ /.yardoc/
19
+ /_yardoc/
20
+ /doc/
21
+ /rdoc/
22
+
23
+ ## Environment normalisation:
24
+ /.bundle/
25
+ /lib/bundler/man/
26
+
27
+ # for a library or gem, you might want to ignore these files since the code is
28
+ # intended to run in multiple environments; otherwise, check them in:
29
+ # Gemfile.lock
30
+ # .ruby-version
31
+ # .ruby-gemset
32
+
33
+ # unless supporting rvm < 1.11.0 or doing something fancy, ignore this:
34
+ .rvmrc
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in brainspace.gemspec
4
+ gemspec
data/Gemfile.lock ADDED
@@ -0,0 +1,37 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ brainspace (0.0.1)
5
+ faraday
6
+ hashie
7
+ json
8
+
9
+ GEM
10
+ remote: https://rubygems.org/
11
+ specs:
12
+ addressable (2.3.6)
13
+ crack (0.4.2)
14
+ safe_yaml (~> 1.0.0)
15
+ faraday (0.9.0)
16
+ multipart-post (>= 1.2, < 3)
17
+ hashie (3.3.1)
18
+ json (1.8.1)
19
+ minitest (5.4.2)
20
+ multipart-post (2.0.0)
21
+ rake (10.3.2)
22
+ safe_yaml (1.0.4)
23
+ vcr (2.9.3)
24
+ webmock (1.19.0)
25
+ addressable (>= 2.3.6)
26
+ crack (>= 0.3.2)
27
+
28
+ PLATFORMS
29
+ ruby
30
+
31
+ DEPENDENCIES
32
+ brainspace!
33
+ bundler (~> 1.3)
34
+ minitest
35
+ rake
36
+ vcr
37
+ webmock
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2014 Disruption Corp.
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
22
+
data/README.md ADDED
@@ -0,0 +1,29 @@
1
+ # Brainspace
2
+
3
+ TODO: Write a gem description
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'brainspace'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install brainspace
18
+
19
+ ## Usage
20
+
21
+ TODO: Write usage instructions here
22
+
23
+ ## Contributing
24
+
25
+ 1. Fork it
26
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
27
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
28
+ 4. Push to the branch (`git push origin my-new-feature`)
29
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,32 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'brainspace/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "brainspace"
8
+ spec.version = Brainspace::VERSION
9
+ spec.authors = ["Fábio Batista"]
10
+ spec.email = ["fbatista@gmail.com"]
11
+ spec.description = %q{Gem to wrap Brainspace API}
12
+ spec.summary = %q{Gem to wrap Brainspace API}
13
+ spec.homepage = ""
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files`.split($/)
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_development_dependency "bundler", "~> 1.3"
22
+ spec.add_development_dependency "rake"
23
+
24
+ spec.add_development_dependency "minitest"
25
+ spec.add_development_dependency "vcr"
26
+ spec.add_development_dependency "webmock"
27
+
28
+ spec.add_dependency "faraday"
29
+ spec.add_dependency "json"
30
+ spec.add_dependency "hashie"
31
+
32
+ end
data/lib/brainspace.rb ADDED
@@ -0,0 +1,24 @@
1
+ require 'hashie'
2
+ require 'faraday'
3
+ require 'json'
4
+
5
+ require_relative "brainspace/version"
6
+ require_relative "brainspace/article"
7
+ require_relative "brainspace/collection"
8
+
9
+ module Brainspace
10
+
11
+ CONFIG = Hashie::Mash.new({
12
+ host: "https://api.brainspace.com",
13
+ user: nil,
14
+ password: nil
15
+ })
16
+
17
+ def self.config
18
+ CONFIG
19
+ end
20
+
21
+ def self.apikey
22
+ @@apikey ||= JSON.parse(Faraday.get("#{config.host}/authenticate", {pass: config.password, user: config.user}).body)['data']
23
+ end
24
+ end
@@ -0,0 +1,13 @@
1
+ require 'hashie'
2
+
3
+ module Brainspace
4
+ class Article
5
+ def initialize(attributes)
6
+ @mash = attributes
7
+ end
8
+
9
+ def method_missing(method_sym, *arguments, &block)
10
+ @mash.send(method_sym)
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,39 @@
1
+ require 'faraday'
2
+ require 'json'
3
+ require 'hashie'
4
+
5
+ module Brainspace
6
+ class Collection
7
+ def initialize(attributes)
8
+ @mash = attributes
9
+ end
10
+
11
+ def method_missing(method_sym, *arguments, &block)
12
+ @mash.send(method_sym)
13
+ end
14
+
15
+ def discovery
16
+ Brainspace::Collection.discovery(@mash.id)
17
+ end
18
+
19
+ def self.all
20
+ response = Faraday.get("#{Brainspace.config.host}/collections", apikey: Brainspace.apikey)
21
+ result = JSON.parse(response.body)
22
+ collections = Hashie::Mash.new(result).collections
23
+ collections.map { |collection| new(collection) }
24
+ end
25
+
26
+ def self.find(id)
27
+ response = Faraday.get("#{Brainspace.config.host}/collections/#{id}", apikey: Brainspace.apikey)
28
+ result = Hashie::Mash.new(JSON.parse(response.body))
29
+ new(result.collection)
30
+ end
31
+
32
+ def self.discovery(id)
33
+ response = Faraday.get("#{Brainspace.config.host}/discovery/collection/#{id}", apikey: Brainspace.apikey)
34
+ result = JSON.parse(response.body)
35
+ articles = Hashie::Mash.new(result).data.article_results.articles
36
+ articles.map { |article| Brainspace::Article.new(article) }
37
+ end
38
+ end
39
+ end
@@ -0,0 +1,3 @@
1
+ module Brainspace
2
+ VERSION = "0.1.0"
3
+ end
@@ -0,0 +1,60 @@
1
+ require './test/test_helper'
2
+
3
+ class BrainspaceCollectionTest < Minitest::Test
4
+
5
+ def setup
6
+ Brainspace.config.user = 'dummy@dummy.com'
7
+ Brainspace.config.password = 'DUMMY'
8
+
9
+ VCR.use_cassette('auth') do
10
+ Brainspace.apikey
11
+ end
12
+
13
+ end
14
+
15
+ def test_exists
16
+ assert Brainspace::Collection
17
+ end
18
+
19
+ def test_it_gives_back_a_single_collection
20
+ VCR.use_cassette('bitcoin_colleciton') do
21
+ collection = Brainspace::Collection.find(3713)
22
+ assert_equal Brainspace::Collection, collection.class
23
+
24
+ # Check that the fields are accessible by our model
25
+ assert_equal "3713", collection.id
26
+ assert_equal "100084", collection.user_id
27
+ assert_equal "Bitcoin", collection.name
28
+ assert_equal "http://www.bitcoincasino.org/wp-content/uploads/2013/07/bitcoin1.jpg", collection.image
29
+ assert_equal "", collection.description
30
+ assert collection.meta_data
31
+ assert_equal "#00A7FF", collection.meta_data.color
32
+ assert_equal 5, collection.item_count
33
+
34
+ end
35
+ end
36
+
37
+ def test_it_returns_all_collections
38
+ VCR.use_cassette('all_collections') do
39
+ result = Brainspace::Collection.all
40
+
41
+ # Make sure we got all the cars
42
+ assert_equal 11, result.length
43
+
44
+ # Make sure that the JSON was parsed
45
+ assert result.kind_of?(Array)
46
+ assert result.first.kind_of?(Brainspace::Collection)
47
+ end
48
+ end
49
+
50
+ def test_it_discovers_articles
51
+ VCR.use_cassette('discovery') do
52
+ result = Brainspace::Collection.discovery(3713)
53
+
54
+ assert_equal 18, result.length
55
+
56
+ assert result.kind_of?(Array)
57
+ assert result.first.kind_of?(Brainspace::Article)
58
+ end
59
+ end
60
+ end
@@ -0,0 +1,393 @@
1
+ ---
2
+ http_interactions:
3
+ - request:
4
+ method: get
5
+ uri: https://api.brainspace.com/collections?apikey=542ef5b7e3e72f2344df4d72
6
+ body:
7
+ encoding: US-ASCII
8
+ string: ''
9
+ headers:
10
+ User-Agent:
11
+ - Faraday v0.9.0
12
+ Accept-Encoding:
13
+ - gzip;q=1.0,deflate;q=0.6,identity;q=0.3
14
+ Accept:
15
+ - '*/*'
16
+ response:
17
+ status:
18
+ code: 200
19
+ message: OK
20
+ headers:
21
+ Access-Control-Allow-Headers:
22
+ - X-Requested-With,Content-Type,Accept,X-CSRF-Token
23
+ Access-Control-Allow-Methods:
24
+ - GET, PUT, POST, PATCH, DELETE, OPTIONS
25
+ Access-Control-Allow-Origin:
26
+ - '*'
27
+ Content-Type:
28
+ - application/json; charset=utf-8
29
+ Date:
30
+ - Fri, 03 Oct 2014 19:15:04 GMT
31
+ Etag:
32
+ - '"276995971"'
33
+ Server:
34
+ - nginx/1.4.6 (Ubuntu)
35
+ X-Powered-By:
36
+ - Express
37
+ Content-Length:
38
+ - '7591'
39
+ Connection:
40
+ - keep-alive
41
+ body:
42
+ encoding: UTF-8
43
+ string: |-
44
+ {
45
+ "success": true,
46
+ "count": 11,
47
+ "collections": [
48
+ {
49
+ "id": "3712",
50
+ "userId": "100084",
51
+ "name": "E-Commerce",
52
+ "image": "http://www.alleywatch.com/wp-content/uploads/2013/04/e-commerce.jpg",
53
+ "description": "",
54
+ "metaData": {
55
+ "color": "#00A7FF",
56
+ "ent_id": null
57
+ },
58
+ "itemCount": 1,
59
+ "aclInfo": {
60
+ "name": "Owner",
61
+ "aclEntries": [
62
+ {
63
+ "principal": "USER:100084",
64
+ "permissions": [
65
+ "ALL"
66
+ ]
67
+ },
68
+ {
69
+ "principal": "USER:0",
70
+ "permissions": [
71
+ "READ"
72
+ ]
73
+ }
74
+ ]
75
+ },
76
+ "referenceId": null,
77
+ "type": "COLLECTION"
78
+ },
79
+ {
80
+ "id": "3714",
81
+ "userId": "100084",
82
+ "name": "Edtech",
83
+ "image": "http://www.avatargeneration.com/wp-content/uploads/2013/01/edtech.jpg",
84
+ "description": "",
85
+ "metaData": {
86
+ "color": "#6D9AEC",
87
+ "ent_id": null
88
+ },
89
+ "itemCount": 2,
90
+ "aclInfo": {
91
+ "name": "Owner",
92
+ "aclEntries": [
93
+ {
94
+ "principal": "USER:100084",
95
+ "permissions": [
96
+ "ALL"
97
+ ]
98
+ },
99
+ {
100
+ "principal": "USER:0",
101
+ "permissions": [
102
+ "READ"
103
+ ]
104
+ }
105
+ ]
106
+ },
107
+ "referenceId": null,
108
+ "type": "COLLECTION"
109
+ },
110
+ {
111
+ "id": "3716",
112
+ "userId": "100084",
113
+ "name": "Entertainment",
114
+ "image": "http://4.bp.blogspot.com/-wse_5qTgjsA/TwPfmcaRPxI/AAAAAAAAAUo/8sMz-XzxhqE/s1600/entertainment.jpg",
115
+ "description": "",
116
+ "metaData": {
117
+ "color": "#A3CD5B",
118
+ "ent_id": null
119
+ },
120
+ "itemCount": 1,
121
+ "aclInfo": {
122
+ "name": "Owner",
123
+ "aclEntries": [
124
+ {
125
+ "principal": "USER:100084",
126
+ "permissions": [
127
+ "ALL"
128
+ ]
129
+ },
130
+ {
131
+ "principal": "USER:0",
132
+ "permissions": [
133
+ "READ"
134
+ ]
135
+ }
136
+ ]
137
+ },
138
+ "referenceId": null,
139
+ "type": "COLLECTION"
140
+ },
141
+ {
142
+ "id": "3717",
143
+ "userId": "100084",
144
+ "name": "Fintech",
145
+ "image": "http://www.bediseno.cl/imagenes/logo-fintech02.jpg",
146
+ "description": "",
147
+ "metaData": {
148
+ "color": "#1F72B8",
149
+ "ent_id": null
150
+ },
151
+ "itemCount": 4,
152
+ "aclInfo": {
153
+ "name": "Owner",
154
+ "aclEntries": [
155
+ {
156
+ "principal": "USER:100084",
157
+ "permissions": [
158
+ "ALL"
159
+ ]
160
+ },
161
+ {
162
+ "principal": "USER:0",
163
+ "permissions": [
164
+ "READ"
165
+ ]
166
+ }
167
+ ]
168
+ },
169
+ "referenceId": null,
170
+ "type": "COLLECTION"
171
+ },
172
+ {
173
+ "id": "3718",
174
+ "userId": "100084",
175
+ "name": "Food&Beverage",
176
+ "image": "http://www.angkormiracle.com/userfiles/food-beverage.jpg",
177
+ "description": "",
178
+ "metaData": {
179
+ "color": "#6700C7",
180
+ "ent_id": null
181
+ },
182
+ "itemCount": 5,
183
+ "aclInfo": {
184
+ "name": "Owner",
185
+ "aclEntries": [
186
+ {
187
+ "principal": "USER:100084",
188
+ "permissions": [
189
+ "ALL"
190
+ ]
191
+ },
192
+ {
193
+ "principal": "USER:0",
194
+ "permissions": [
195
+ "READ"
196
+ ]
197
+ }
198
+ ]
199
+ },
200
+ "referenceId": null,
201
+ "type": "COLLECTION"
202
+ },
203
+ {
204
+ "id": "3720",
205
+ "userId": "100084",
206
+ "name": "Media",
207
+ "image": "http://www.bpsos.org/mainsite/images/media.gif",
208
+ "description": "",
209
+ "metaData": {
210
+ "color": "#00B488",
211
+ "ent_id": null
212
+ },
213
+ "itemCount": 0,
214
+ "aclInfo": {
215
+ "name": "Owner",
216
+ "aclEntries": [
217
+ {
218
+ "principal": "USER:100084",
219
+ "permissions": [
220
+ "ALL"
221
+ ]
222
+ },
223
+ {
224
+ "principal": "USER:0",
225
+ "permissions": [
226
+ "READ"
227
+ ]
228
+ }
229
+ ]
230
+ },
231
+ "referenceId": null,
232
+ "type": "COLLECTION"
233
+ },
234
+ {
235
+ "id": "3713",
236
+ "userId": "100084",
237
+ "name": "Bitcoin",
238
+ "image": "http://www.bitcoincasino.org/wp-content/uploads/2013/07/bitcoin1.jpg",
239
+ "description": "",
240
+ "metaData": {
241
+ "color": "#00A7FF",
242
+ "ent_id": null
243
+ },
244
+ "itemCount": 5,
245
+ "aclInfo": {
246
+ "name": "Owner",
247
+ "aclEntries": [
248
+ {
249
+ "principal": "USER:100084",
250
+ "permissions": [
251
+ "ALL"
252
+ ]
253
+ },
254
+ {
255
+ "principal": "USER:0",
256
+ "permissions": [
257
+ "READ"
258
+ ]
259
+ }
260
+ ]
261
+ },
262
+ "referenceId": null,
263
+ "type": "COLLECTION"
264
+ },
265
+ {
266
+ "id": "3715",
267
+ "userId": "100084",
268
+ "name": "Energy",
269
+ "image": "http://www.rochelleallison.com/wp-content/uploads/2011/06/smart-energy1.jpg",
270
+ "description": "",
271
+ "metaData": {
272
+ "color": "#091234",
273
+ "ent_id": null
274
+ },
275
+ "itemCount": 1,
276
+ "aclInfo": {
277
+ "name": "Owner",
278
+ "aclEntries": [
279
+ {
280
+ "principal": "USER:100084",
281
+ "permissions": [
282
+ "ALL"
283
+ ]
284
+ },
285
+ {
286
+ "principal": "USER:0",
287
+ "permissions": [
288
+ "READ"
289
+ ]
290
+ }
291
+ ]
292
+ },
293
+ "referenceId": null,
294
+ "type": "COLLECTION"
295
+ },
296
+ {
297
+ "id": "3719",
298
+ "userId": "100084",
299
+ "name": "Mobile",
300
+ "image": "http://mobilemagnet.files.wordpress.com/2010/10/latest-mobile-phones1.jpg",
301
+ "description": "",
302
+ "metaData": {
303
+ "color": "#49B6E9",
304
+ "ent_id": null
305
+ },
306
+ "itemCount": 1,
307
+ "aclInfo": {
308
+ "name": "Owner",
309
+ "aclEntries": [
310
+ {
311
+ "principal": "USER:100084",
312
+ "permissions": [
313
+ "ALL"
314
+ ]
315
+ },
316
+ {
317
+ "principal": "USER:0",
318
+ "permissions": [
319
+ "READ"
320
+ ]
321
+ }
322
+ ]
323
+ },
324
+ "referenceId": null,
325
+ "type": "COLLECTION"
326
+ },
327
+ {
328
+ "id": "3721",
329
+ "userId": "100084",
330
+ "name": "Mobility",
331
+ "image": "",
332
+ "description": "",
333
+ "metaData": {
334
+ "color": "#A3CD5B",
335
+ "ent_id": null
336
+ },
337
+ "itemCount": 4,
338
+ "aclInfo": {
339
+ "name": "Owner",
340
+ "aclEntries": [
341
+ {
342
+ "principal": "USER:100084",
343
+ "permissions": [
344
+ "ALL"
345
+ ]
346
+ },
347
+ {
348
+ "principal": "USER:0",
349
+ "permissions": [
350
+ "READ"
351
+ ]
352
+ }
353
+ ]
354
+ },
355
+ "referenceId": null,
356
+ "type": "COLLECTION"
357
+ },
358
+ {
359
+ "id": "3722",
360
+ "userId": "100084",
361
+ "name": "Health Care",
362
+ "image": "http://blog.telecom.toshiba.com/wp-content/uploads/2011/06/health-care.jpg",
363
+ "description": "",
364
+ "metaData": {
365
+ "color": "#091234",
366
+ "ent_id": null
367
+ },
368
+ "itemCount": 6,
369
+ "aclInfo": {
370
+ "name": "Owner",
371
+ "aclEntries": [
372
+ {
373
+ "principal": "USER:100084",
374
+ "permissions": [
375
+ "ALL"
376
+ ]
377
+ },
378
+ {
379
+ "principal": "USER:0",
380
+ "permissions": [
381
+ "READ"
382
+ ]
383
+ }
384
+ ]
385
+ },
386
+ "referenceId": null,
387
+ "type": "COLLECTION"
388
+ }
389
+ ]
390
+ }
391
+ http_version:
392
+ recorded_at: Fri, 03 Oct 2014 19:15:13 GMT
393
+ recorded_with: VCR 2.9.3