k_sequencing 0.1.3 → 0.1.4

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: d1c8b30eacc43a71ebaf56c5d83b8d1d20ff9d2d
4
- data.tar.gz: c7c27265ef43c139dff1731efc1218b4f74f2564
3
+ metadata.gz: 414c884c2a6378b04c87a4bb7596d1a814c07089
4
+ data.tar.gz: d44b2deee17b7fb26bbf2d1281c476856bf6ba27
5
5
  SHA512:
6
- metadata.gz: 3b22a5b7de6d957077cf376ce76fd0c516c3013f6d703f621db38925d10225717ff51fd81944bfecd9a6a6567ea60be508b97f167ba9afff7746ca1ff1ba80b3
7
- data.tar.gz: 105a48c085ba2988fde81a0530e9b7eebbf819384a088c9478793aa39e531b330c357c39a2ec5e22da9cd82583419ef872ce6885ab52548108071e2816373f05
6
+ metadata.gz: 0cf5b038df68fcb995e169144cdb5c90d68231cd36547498596c43341402817932a797697850dbb49c0d685aebe99152286b604c6bdda00bf4911d56c479bdeb
7
+ data.tar.gz: c6166361a1e83077ca1fb16fc00603ccbbeec33a4fc6de35c8706faed44895a2def7230f0082562cbce3576a4f07cc5f1c5f14c77e171568411e3d5120823940
data/.gitignore CHANGED
@@ -1 +1,2 @@
1
1
  *.gem
2
+ *.DS_Store
data/README.md CHANGED
@@ -4,12 +4,20 @@ Image and content moderation services.
4
4
 
5
5
  ## Getting Started
6
6
 
7
- KSequencing 0.1.3 works with Rails 4.1 onwards. You can add it to your Gemfile with:
7
+ KSequencing 0.1.4 works with Rails 4.1 onwards. You can add it to your Gemfile with:
8
8
  ```ruby
9
9
  gem 'k_sequencing'
10
10
  ```
11
11
  Then run bundle install
12
12
 
13
+ Next, you need to run the generator:
14
+
15
+ ```console
16
+ $ rails generate k_sequencing:install
17
+ ```
18
+
19
+ The generator will install an initializer which describes ALL of KSequencing's configuration options. It is *imperative* that you take a look at it. When you are done, you are ready to add KSqeuencing to any of your codes.
20
+
13
21
  You have to contact us [Datawow](https://datawow.io/pages/contact) to get your token. With this token you'll be able to use our gem properly.
14
22
 
15
23
  ## Usage
@@ -21,7 +29,6 @@ KSequencing.client.get_image_closed_question()
21
29
 
22
30
  | Field | Type | Required | Description |
23
31
  | ------------- |:-------------:| :----:| :-----|
24
- | token | string | Yes |Project Authorization Token|
25
32
  | id | string | No | Image id|
26
33
  |custom_id | string | No | Client's image id |
27
34
 
@@ -30,7 +37,6 @@ Note: You must choose id or custom_id for search. Not both.
30
37
  Sample request
31
38
  ```ruby
32
39
  KSequencing.client.get_image_closed_question(
33
- token: "9UPmGGWEwBsJrVnw6844tfpd",
34
40
  id: "59311194e99991b2ca8979f1"
35
41
  )
36
42
  ```
@@ -69,7 +75,6 @@ KSequencing.client.create_image_closed_questions()
69
75
  ```
70
76
  | Field | Type | Required | Description |
71
77
  | ------------- |:-------------:| :-----:| :-----|
72
- | token | string | Yes |User Authorization Token|
73
78
  | data | string | Yes |Data for moderate|
74
79
  | postback_url | string | No | Image postback url|
75
80
  | postback_method | string | No |Postback method|
@@ -79,7 +84,6 @@ Sample request
79
84
 
80
85
  ```ruby
81
86
  KSequencing.client.create_image_closed_questions(
82
- token: "9UPmGGWEwBsJrVnw6844tfpd",
83
87
  data: "image_url"
84
88
  )
85
89
  ```
@@ -14,7 +14,6 @@ KSequencing.client.get_image_closed_question()
14
14
 
15
15
  | Field | Type | Required | Description |
16
16
  | ------------- |:-------------:| :----:| :-----|
17
- | token | string | Yes |Project Authorization Token|
18
17
  | id | string | No | Image id|
19
18
  | custom_id | string | No | Client's image id |
20
19
 
@@ -23,7 +22,6 @@ Note: You must choose id or custom_id for search. Not both.
23
22
  Sample request
24
23
  ```ruby
25
24
  KSequencing.client.get_image_closed_question(
26
- token: "9UPmGGWEwBsJrVnw6844tfpd",
27
25
  id: "59311194e99991b2ca8979f1"
28
26
  )
29
27
  ```
@@ -62,7 +60,6 @@ KSequencing.client.create_image_closed_questions()
62
60
  ```
63
61
  | Field | Type | Required | Description |
64
62
  | ------------- |:-------------:| :-----:| :-----|
65
- | token | string | Yes |Project Authorization Token|
66
63
  | data | string | Yes |Data for moderate|
67
64
  | postback_url | string | No | Image postback url|
68
65
  | postback_method | string | No |Postback method|
@@ -71,7 +68,6 @@ KSequencing.client.create_image_closed_questions()
71
68
  Sample request
72
69
  ```ruby
73
70
  KSequencing.client.create_image_closed_questions(
74
- token: "9UPmGGWEwBsJrVnw6844tfpd",
75
71
  data: "image_url"
76
72
  )
77
73
  ```
@@ -110,7 +106,6 @@ KSequencing.client.get_image_choice()
110
106
 
111
107
  | Field | Type | Required | Description |
112
108
  | ------------- |:-------------:| :----:| :-----|
113
- | token | string | Yes |Project Authorization Token|
114
109
  | id | string | No | Image id|
115
110
  |custom_id | string | No | Client's image id |
116
111
 
@@ -119,7 +114,6 @@ Note: You must choose id or custom_id for search. Not both.
119
114
  Sample request
120
115
  ```ruby
121
116
  KSequencing.client.get_image_choice(
122
- token: "9UPmGGWEwBsJrVnw6844tfpd",
123
117
  id: "59311194e99991b2ca8979f1"
124
118
  )
125
119
  ```
@@ -166,7 +160,6 @@ KSequencing.client.create_image_choices()
166
160
  ```
167
161
  | Field | Type | Required | Description |
168
162
  | ------------- |:-------------:| :-----:| :-----|
169
- | token | string | Yes |Project Authorization Token|
170
163
  | instruction | string | Yes | Image instruction|
171
164
  |categories | Array[string] | Yes | Categories of answers |
172
165
  | data | string | Yes |Data for attachment|
@@ -182,7 +175,6 @@ Sample request
182
175
  For one answer
183
176
  ```ruby
184
177
  KSequencing.client.create_image_choices(
185
- token: "9UPmGGWEwBsJrVnw6844tfpd",
186
178
  instruction: "question",
187
179
  categories: ["options1", "options2", "options3"],
188
180
  data: "image_url"
@@ -191,7 +183,6 @@ KSequencing.client.create_image_choices(
191
183
  For multiple answer
192
184
  ```ruby
193
185
  KSequencing.client.create_image_choices(
194
- token: "9UPmGGWEwBsJrVnw6844tfpd",
195
186
  instruction: "question",
196
187
  categories: ["options1", "options2", "options3"],
197
188
  data: "image_url"
@@ -241,7 +232,6 @@ KSequencing.client.get_image_message()
241
232
 
242
233
  | Field | Type | Required | Description |
243
234
  | ------------- |:-------------:| :----:| :-----|
244
- | token | string | Yes |Project Authorization Token|
245
235
  | id | string | No | Image id|
246
236
  |custom_id | string | No | Client's image id |
247
237
 
@@ -250,7 +240,6 @@ Note: You must choose id or custom_id for search. Not both.
250
240
  Sample request
251
241
  ```ruby
252
242
  KSequencing.client.get_image_message(
253
- token: "9UPmGGWEwBsJrVnw6844tfpd",
254
243
  id: "592fbfce1b9d8f69e4178688"
255
244
  )
256
245
  ```
@@ -290,7 +279,6 @@ KSequencing.client.create_image_messages()
290
279
  ```
291
280
  | Field | Type | Required | Description |
292
281
  | ------------- |:-------------:| :-----:| :-----|
293
- | token | string | Yes |Project Authorization Token|
294
282
  | instruction | string | Yes | Image instruction|
295
283
  | data | string | Yes |Data for attachment|
296
284
  | postback_url | string | No | Image postback url|
@@ -300,7 +288,6 @@ KSequencing.client.create_image_messages()
300
288
  Sample request
301
289
  ```ruby
302
290
  KSequencing.client.create_image_messages(
303
- token: "9UPmGGWEwBsJrVnw6844tfpd",
304
291
  instruction: "question",
305
292
  data: "image_url"
306
293
  )
@@ -341,7 +328,6 @@ KSequencing.client.get_image_photo_tag()
341
328
 
342
329
  | Field | Type | Required | Description |
343
330
  | ------------- |:-------------:| :----:| :-----|
344
- | token | string | Yes |Project Authorization Token|
345
331
  | id | string | No | Image id|
346
332
  |custom_id | string | No | Client's image id |
347
333
 
@@ -350,7 +336,6 @@ Note: You must choose id or custom_id for search. Not both.
350
336
  Sample request
351
337
  ```ruby
352
338
  KSequencing.client.get_image_photo_tag(
353
- token: "9UPmGGWEwBsJrVnw6844tfpd",
354
339
  id: "592fbfec1b9d8f69e4178689"
355
340
  )
356
341
  ```
@@ -390,7 +375,6 @@ KSequencing.client.create_image_photo_tags()
390
375
  ```
391
376
  | Field | Type | Required | Description |
392
377
  | ------------- |:-------------:| :-----:| :-----|
393
- | token | string | Yes |Project Authorization Token|
394
378
  | instruction | string | Yes | Image instruction|
395
379
  | data | string | Yes |Data for attachment|
396
380
  | postback_url | string | No | Image postback url|
@@ -400,7 +384,6 @@ KSequencing.client.create_image_photo_tags()
400
384
  Sample request
401
385
  ```ruby
402
386
  KSequencing.client.create_image_photo_tags(
403
- token: "9UPmGGWEwBsJrVnw6844tfpd",
404
387
  instruction: "question",
405
388
  data: "image_url"
406
389
  )
data/k_sequencing.gemspec CHANGED
@@ -1,10 +1,11 @@
1
1
  # coding: utf-8
2
+
2
3
  lib = File.expand_path('../lib', __FILE__)
3
4
  $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
5
 
5
6
  Gem::Specification.new do |s|
6
7
  s.name = 'k_sequencing'
7
- s.version = '0.1.3'
8
+ s.version = '0.1.4'
8
9
  s.date = '2017-05-24'
9
10
  s.summary = 'KSequencing is a moderator service for your online content'
10
11
  s.description = 'Moderation suite'
@@ -0,0 +1,18 @@
1
+ require 'rails/generators/base'
2
+ require 'securerandom'
3
+
4
+ module KSequencing
5
+ module Generators
6
+ # :nodoc:
7
+ class InstallGenerator < Rails::Generators::Base
8
+ source_root File.expand_path('../../templates', __FILE__)
9
+
10
+ desc 'Creates a KSequencing initializer
11
+ and copy locale files to your application.'
12
+
13
+ def copy_initializer
14
+ template 'k_sequencing.rb', 'config/initializers/k_sequencing.rb'
15
+ end
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,5 @@
1
+ KSequencing.setup do |config|
2
+ # ==> Secret key Configuration
3
+ # You can change it below and use your own secret key.
4
+ config.project_key = 'Project token key'
5
+ end
@@ -1,37 +1,44 @@
1
1
  module KSequencing
2
-
2
+ # :nodoc:
3
3
  class Client
4
-
5
4
  def create_image_choices(options = {})
6
- connection.post("/api/images/choices", options)
5
+ options[:token] = KSequencing.project_key
6
+ connection.post('/api/images/choices', options)
7
7
  end
8
8
 
9
9
  def create_image_closed_questions(options = {})
10
- connection.post("/api/images/closed_questions", options)
10
+ options[:token] = KSequencing.project_key
11
+ connection.post('/api/images/closed_questions', options)
11
12
  end
12
13
 
13
14
  def create_image_messages(options = {})
14
- connection.post("/api/images/messages", options)
15
+ options[:token] = KSequencing.project_key
16
+ connection.post('/api/images/messages', options)
15
17
  end
16
18
 
17
19
  def create_image_photo_tags(options = {})
18
- connection.post("/api/images/photo_tags", options)
20
+ options[:token] = KSequencing.project_key
21
+ connection.post('/api/images/photo_tags', options)
19
22
  end
20
23
 
21
24
  def get_image_choice(options = {})
22
- connection.get("/api/images/choice", options)
25
+ options[:token] = KSequencing.project_key
26
+ connection.get('/api/images/choice', options)
23
27
  end
24
28
 
25
29
  def get_image_closed_question(options = {})
26
- connection.get("/api/images/closed_question", options)
30
+ options[:token] = KSequencing.project_key
31
+ connection.get('/api/images/closed_question', options)
27
32
  end
28
33
 
29
34
  def get_image_message(options = {})
30
- connection.get("/api/images/message", options)
35
+ options[:token] = KSequencing.project_key
36
+ connection.get('/api/images/message', options)
31
37
  end
32
38
 
33
39
  def get_image_photo_tag(options = {})
34
- connection.get("/api/images/photo_tag", options)
40
+ options[:token] = KSequencing.project_key
41
+ connection.get('/api/images/photo_tag', options)
35
42
  end
36
43
 
37
44
  private
@@ -39,7 +46,5 @@ module KSequencing
39
46
  def connection
40
47
  @connection ||= Connection.new
41
48
  end
42
-
43
49
  end
44
-
45
50
  end
@@ -1,19 +1,18 @@
1
- require File.expand_path("../faraday/raise_http_exception.rb", __FILE__)
2
- require File.expand_path("../client_response.rb", __FILE__)
1
+ require File.expand_path('../faraday/raise_http_exception.rb', __FILE__)
2
+ require File.expand_path('../client_response.rb', __FILE__)
3
3
  require 'active_support/all'
4
4
 
5
5
  module KSequencing
6
-
6
+ # :nodoc:
7
7
  class Connection
8
-
9
8
  def get(path, options = {})
10
9
  response = connection.get do |request|
11
10
  request.url(path)
12
- request.headers["Content-Type"] = "application/json"
13
- request.headers["Authorization"] = options[:token] unless options[:token].nil?
11
+ request.headers['Content-Type'] = 'application/json'
12
+ request.headers['Authorization'] = options[:token] unless options[:token].nil?
14
13
  request.params = options
15
14
  end
16
- Response.new(data(response), true, response.status, "success", meta(response), total(response))
15
+ Response.new(data(response), true, response.status, 'success', meta(response), total(response))
17
16
  rescue Error, Faraday::Error => e
18
17
  handle_error(e)
19
18
  end
@@ -21,8 +20,8 @@ module KSequencing
21
20
  def post(path, options = {}, query_params = {})
22
21
  response = connection.post do |request|
23
22
  request.path = path
24
- request.headers["Content-Type"] = "application/json"
25
- request.headers["Authorization"] = options[:token] unless options[:token].nil?
23
+ request.headers['Content-Type'] = 'application/json'
24
+ request.headers['Authorization'] = options[:token] unless options[:token].nil?
26
25
  request.params = query_params
27
26
  request.body = options unless options.empty?
28
27
  end
@@ -49,29 +48,27 @@ module KSequencing
49
48
  end
50
49
 
51
50
  def meta(response)
52
- response.body["meta"]
51
+ response.body['meta']
53
52
  end
54
53
 
55
54
  def total(response)
56
- meta(response)["count"] if meta(response).present?
55
+ meta(response)['count'] if meta(response).present?
57
56
  end
58
57
 
59
58
  def data(response)
60
- response.body["data"]
59
+ response.body['data']
61
60
  end
62
61
 
63
62
  def handle_error(exception)
64
63
  if exception.is_a?(Faraday::ConnectionFailed)
65
64
  code = 599
66
- message = "Connection Failed"
65
+ message = 'Connection Failed'
67
66
  else
68
- code = exception.to_s.partition(":").first
69
- message = exception.to_s.partition(":").last
67
+ code = exception.to_s.partition(':').first
68
+ message = exception.to_s.partition(':').last
70
69
  end
71
70
 
72
71
  Response.new(nil, false, code, message, 0)
73
72
  end
74
-
75
73
  end
76
-
77
74
  end
@@ -1,3 +1,3 @@
1
1
  module KSequencing
2
- VERSION = '0.1.3'
2
+ VERSION = '0.1.4'.freeze
3
3
  end
data/lib/k_sequencing.rb CHANGED
@@ -4,8 +4,17 @@ require_relative 'k_sequencing/connection'
4
4
  require_relative 'k_sequencing/error'
5
5
  require_relative 'k_sequencing/version'
6
6
 
7
+ # :nodoc:
7
8
  module KSequencing
8
- def self.client
9
- Client.new
9
+ mattr_accessor :user_key, :project_key
10
+
11
+ class << self
12
+ def setup
13
+ yield self
14
+ end
15
+
16
+ def client
17
+ Client.new
18
+ end
10
19
  end
11
20
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: k_sequencing
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.3
4
+ version: 0.1.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jesdakorn Samittiauttakorn
@@ -98,6 +98,8 @@ files:
98
98
  - Rakefile
99
99
  - docs/documentation.md
100
100
  - k_sequencing.gemspec
101
+ - lib/generators/k_sequencing/install_generator.rb
102
+ - lib/generators/templates/k_sequencing.rb
101
103
  - lib/k_sequencing.rb
102
104
  - lib/k_sequencing/client.rb
103
105
  - lib/k_sequencing/client_response.rb