k_sequencing 0.1.24 → 0.1.25

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.
Files changed (38) hide show
  1. checksums.yaml +5 -5
  2. data/.gitignore +4 -0
  3. data/.rubocop.yml +23 -0
  4. data/Gemfile +1 -1
  5. data/Gemfile.lock +27 -1
  6. data/README.md +17 -9
  7. data/Rakefile +12 -2
  8. data/docs/documentation.md +32 -35
  9. data/k_sequencing.gemspec +8 -6
  10. data/lib/k_sequencing.rb +0 -4
  11. data/lib/k_sequencing/client.rb +1 -3
  12. data/lib/k_sequencing/client_response.rb +4 -9
  13. data/lib/k_sequencing/connection.rb +24 -16
  14. data/lib/k_sequencing/faraday/raise_http_exception.rb +2 -8
  15. data/lib/k_sequencing/predictions.rb +2 -4
  16. data/lib/k_sequencing/version.rb +1 -1
  17. data/test/fixtures/image_choice/all.json +27 -0
  18. data/test/fixtures/image_choice/create.json +25 -0
  19. data/test/fixtures/image_closed_question/all.json +21 -0
  20. data/test/fixtures/image_closed_question/create.json +19 -0
  21. data/test/fixtures/image_message/all.json +22 -0
  22. data/test/fixtures/image_message/create.json +20 -0
  23. data/test/fixtures/image_photo_tag/all.json +22 -0
  24. data/test/fixtures/image_photo_tag/create.json +20 -0
  25. data/test/fixtures/prediction/all.json +21 -0
  26. data/test/fixtures/prediction/create.json +19 -0
  27. data/test/helper/file_reader.rb +11 -0
  28. data/test/k_sequencing/client_response_test.rb +29 -0
  29. data/test/k_sequencing/client_test.rb +189 -0
  30. data/test/k_sequencing/connection_test.rb +85 -0
  31. data/test/k_sequencing/image_choices_test.rb +38 -0
  32. data/test/k_sequencing/image_closed_questions_test.rb +38 -0
  33. data/test/k_sequencing/image_messages_test.rb +38 -0
  34. data/test/k_sequencing/image_photo_tags_test.rb +38 -0
  35. data/test/k_sequencing/predictions_test.rb +39 -0
  36. data/test/k_sequencing_test.rb +39 -0
  37. data/test/test_helper.rb +41 -0
  38. metadata +101 -17
@@ -1,12 +1,10 @@
1
- # coding: utf-8
2
-
3
1
  lib = File.expand_path('../lib', __FILE__)
4
2
  $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
5
3
 
6
4
  Gem::Specification.new do |s|
7
5
  s.name = 'k_sequencing'
8
- s.version = '0.1.24'
9
- s.date = '2017-12-27'
6
+ s.version = '0.1.25'
7
+ s.date = '2018-03-28'
10
8
  s.summary = 'KSequencing is a moderator service for your online content'
11
9
  s.description = 'Moderation suite'
12
10
  s.post_install_message = File.read('INSTALL.md') if File.exist?('INSTALL.md')
@@ -17,7 +15,11 @@ Gem::Specification.new do |s|
17
15
  s.license = 'Commercial'
18
16
  s.require_paths = ['lib']
19
17
 
20
- s.add_runtime_dependency 'json', '~> 1.8', '>= 1.8.3'
21
- s.add_runtime_dependency 'faraday', '~> 0.13.1', '>= 0.13.1'
18
+ s.add_runtime_dependency 'faraday', '~> 0.13.1', '>= 0.13.1'
22
19
  s.add_runtime_dependency 'faraday_middleware', '~> 0.12.2', '>= 0.12.2'
20
+ s.add_runtime_dependency 'json', '~> 1.8', '>= 1.8.3'
21
+ s.add_development_dependency 'minitest', '~> 5.11', '>= 5.11.3'
22
+ s.add_development_dependency 'rake', '~> 12.3'
23
+ s.add_development_dependency 'simplecov', '~> 0.15.1'
24
+ s.add_development_dependency 'webmock', '~> 3.3'
23
25
  end
@@ -10,8 +10,6 @@ require_relative 'k_sequencing/image_messages'
10
10
  require_relative 'k_sequencing/predictions'
11
11
  # :nodoc:
12
12
  module KSequencing
13
- mattr_accessor :user_key, :project_key
14
-
15
13
  class << self
16
14
  def setup
17
15
  yield self
@@ -40,7 +38,5 @@ module KSequencing
40
38
  def prediction
41
39
  Prediction.new
42
40
  end
43
-
44
41
  end
45
-
46
42
  end
@@ -1,7 +1,6 @@
1
1
  module KSequencing
2
2
  # :nodoc:
3
3
  class Client
4
-
5
4
  def create_image_choices(options = {})
6
5
  options[:token] ||= KSequencing.project_key
7
6
  connection.post('/api/images/choices', options)
@@ -84,11 +83,10 @@ module KSequencing
84
83
  connection.get("/api/projects/images/#{id}", options)
85
84
  end
86
85
 
87
- private
86
+ private
88
87
 
89
88
  def connection
90
89
  @connection ||= Connection.new
91
90
  end
92
-
93
91
  end
94
92
  end
@@ -1,23 +1,18 @@
1
1
  module KSequencing
2
-
3
2
  class Response
4
-
5
- attr_reader :count, :message, :status
3
+ attr_reader :total, :message, :status
6
4
  attr_accessor :data, :meta
7
5
 
8
- def initialize(data, success, response_code = "", response_message = "success", meta = nil, total = 0)
6
+ def initialize(data, response_code = '', response_message = 'success', meta = nil, total = 0)
9
7
  @data = data
10
- @success = success
11
8
  @status = response_code
12
9
  @message = response_message
13
- @total = total unless total.nil?
14
10
  @meta = meta
11
+ @total = total unless total.nil?
15
12
  end
16
13
 
17
14
  def successful?
18
- !something.nil?
15
+ [200, 201].include? status
19
16
  end
20
-
21
17
  end
22
-
23
18
  end
@@ -1,31 +1,30 @@
1
1
  require File.expand_path('../faraday/raise_http_exception.rb', __FILE__)
2
2
  require File.expand_path('../client_response.rb', __FILE__)
3
- require 'active_support/all'
4
3
 
5
4
  module KSequencing
6
5
  # :nodoc:
7
6
  class Connection
8
7
  def get(path, options = {})
9
- response = connection.get do |request|
8
+ @response = connection.get do |request|
10
9
  request.url(path)
11
10
  request.headers['Content-Type'] = 'application/json'
12
11
  request.headers['Authorization'] = options[:token] unless options[:token].nil?
13
- request.params = options
12
+ request.params = options[:path_param] ? prediction_options(options) : options
14
13
  end
15
- Response.new(data(response), true, response.status, 'success', meta(response), total(response))
14
+ Response.new(data, status_code, message, meta, total)
16
15
  rescue Error, Faraday::Error => e
17
16
  handle_error(e)
18
17
  end
19
18
 
20
19
  def post(path, options = {}, query_params = {})
21
- response = connection.post do |request|
20
+ @response = connection.post do |request|
22
21
  request.path = path
23
22
  request.headers['Content-Type'] = 'application/json'
24
23
  request.headers['Authorization'] = options[:token] unless options[:token].nil?
25
24
  request.params = query_params
26
- request.body = options unless options.empty?
25
+ request.body = options unless options.nil?
27
26
  end
28
- Response.new(data(response), true, status_code(response), meta(response), meta(response), nil)
27
+ Response.new(data, status_code, message, meta, nil)
29
28
  rescue Error, Faraday::Error => e
30
29
  handle_error(e)
31
30
  end
@@ -47,20 +46,24 @@ module KSequencing
47
46
  end
48
47
  end
49
48
 
50
- def status_code(response)
51
- meta(response)['code'] if meta(response).present?
49
+ def data
50
+ @response.body['data']
52
51
  end
53
52
 
54
- def meta(response)
55
- response.body['meta']
53
+ def meta
54
+ @response.body['meta']
56
55
  end
57
56
 
58
- def total(response)
59
- meta(response)['total_count'] if meta(response).present?
57
+ def status_code
58
+ meta['code'] unless meta.nil?
60
59
  end
61
60
 
62
- def data(response)
63
- response.body['data']
61
+ def message
62
+ meta['message'] unless meta.nil?
63
+ end
64
+
65
+ def total
66
+ meta['total_count'] unless meta.nil?
64
67
  end
65
68
 
66
69
  def handle_error(exception)
@@ -72,7 +75,12 @@ module KSequencing
72
75
  message = exception.to_s.partition(':').last
73
76
  end
74
77
 
75
- Response.new(nil, false, code, message, 0)
78
+ Response.new(nil, code, message, nil)
79
+ end
80
+
81
+ def prediction_options(options)
82
+ %i[id path_param].each { |e| options.delete(e) }
83
+ options
76
84
  end
77
85
  end
78
86
  end
@@ -1,11 +1,8 @@
1
1
  require 'faraday_middleware'
2
2
 
3
3
  module KSequencing
4
-
5
4
  module FaradayMiddleware
6
-
7
5
  class RaiseHttpException < Faraday::Middleware
8
-
9
6
  def call(request_env)
10
7
  @app.call(request_env).on_complete do |response|
11
8
  case response[:status].to_i
@@ -33,14 +30,11 @@ module KSequencing
33
30
  private
34
31
 
35
32
  def error_message(response_body)
36
- if response_body.present? && response_body.is_a?(String)
33
+ if !response_body.nil? && response_body.is_a?(String)
37
34
  response_body = JSON.parse(response_body)
38
- response_body["message"]
35
+ response_body['message']
39
36
  end
40
37
  end
41
-
42
38
  end
43
-
44
39
  end
45
-
46
40
  end
@@ -1,7 +1,6 @@
1
1
  module KSequencing
2
2
  # :nodoc:
3
3
  class Prediction
4
-
5
4
  def all(options = {})
6
5
  options[:token] ||= KSequencing.project_key
7
6
  connection.get('/api/prime/predictions', options)
@@ -14,15 +13,14 @@ module KSequencing
14
13
 
15
14
  def find_by(options = {})
16
15
  options[:token] ||= KSequencing.project_key
16
+ options[:path_param] = true
17
17
  connection.get("/api/prime/predictions/#{options[:id]}", options)
18
18
  end
19
19
 
20
- private
20
+ private
21
21
 
22
22
  def connection
23
23
  @connection ||= Connection.new
24
24
  end
25
-
26
25
  end
27
-
28
26
  end
@@ -1,3 +1,3 @@
1
1
  module KSequencing
2
- VERSION = '0.1.24'.freeze
2
+ VERSION = '0.1.25'.freeze
3
3
  end
@@ -0,0 +1,27 @@
1
+ {
2
+ "data": {
3
+ "images": [
4
+ {
5
+ "id": "5a44671ab3957c2ab5c33326",
6
+ "allow_empty": false,
7
+ "answer": [],
8
+ "categories": [
9
+ "Gnoon"
10
+ ],
11
+ "credit_charged": 0,
12
+ "custom_id": null,
13
+ "data": "https://assets-cdn.github.com/images/modules/open_graph/github-mark.png",
14
+ "instruction": "Instruction",
15
+ "multiple": false,
16
+ "postback_url": "https://9333bbac.ngrok.io/callbacks",
17
+ "processed_at": null,
18
+ "project_id": 102,
19
+ "status": "unprocess"
20
+ }
21
+ ]
22
+ },
23
+ "meta": {
24
+ "code": 200,
25
+ "message": "success"
26
+ }
27
+ }
@@ -0,0 +1,25 @@
1
+ {
2
+ "data": {
3
+ "image": {
4
+ "id": "5a44671ab3957c2ab5c33326",
5
+ "allow_empty": false,
6
+ "answer": [],
7
+ "categories": [
8
+ "foo,bar"
9
+ ],
10
+ "credit_charged": 0,
11
+ "custom_id": null,
12
+ "data": "https://assets-cdn.github.com/images/modules/open_graph/github-mark.png",
13
+ "instruction": "Image's instruction",
14
+ "multiple": false,
15
+ "postback_url": "https://9333bbac.ngrok.io/callbacks",
16
+ "processed_at": null,
17
+ "project_id": 105,
18
+ "status": "unprocess"
19
+ }
20
+ },
21
+ "meta": {
22
+ "code": 200,
23
+ "message": "success"
24
+ }
25
+ }
@@ -0,0 +1,21 @@
1
+ {
2
+ "data": {
3
+ "images": [
4
+ {
5
+ "id": "5a44671ab3957c2ab5c33326",
6
+ "answer": "declined",
7
+ "credit_charged": 1,
8
+ "custom_id": null,
9
+ "data": "https://assets-cdn.github.com/images/modules/open_graph/github-mark.png",
10
+ "postback_url": "https://9333bbac.ngrok.io/callbacks",
11
+ "processed_at": "2017-12-28T10:40:30.462+07:00",
12
+ "project_id": 102,
13
+ "status": "processed"
14
+ }
15
+ ]
16
+ },
17
+ "meta": {
18
+ "code": 200,
19
+ "message": "success"
20
+ }
21
+ }
@@ -0,0 +1,19 @@
1
+ {
2
+ "data": {
3
+ "image": {
4
+ "id": "5a44671ab3957c2ab5c33326",
5
+ "answer": "declined",
6
+ "credit_charged": 1,
7
+ "custom_id": null,
8
+ "data": "https://assets-cdn.github.com/images/modules/open_graph/github-mark.png",
9
+ "postback_url": "https://9333bbac.ngrok.io/callbacks",
10
+ "processed_at": "2017-12-28T10:40:30.462+07:00",
11
+ "project_id": 102,
12
+ "status": "processed"
13
+ }
14
+ },
15
+ "meta": {
16
+ "code": 200,
17
+ "message": "success"
18
+ }
19
+ }
@@ -0,0 +1,22 @@
1
+ {
2
+ "data": {
3
+ "images": [
4
+ {
5
+ "id": "5a44671ab3957c2ab5c33326",
6
+ "answer": null,
7
+ "credit_charged": 0,
8
+ "custom_id": null,
9
+ "data": "https://assets-cdn.github.com/images/modules/open_graph/github-mark.png",
10
+ "instruction": "Instruction",
11
+ "postback_url": "https://9333bbac.ngrok.io/callbacks",
12
+ "processed_at": null,
13
+ "project_id": 102,
14
+ "status": "unprocess"
15
+ }
16
+ ]
17
+ },
18
+ "meta": {
19
+ "code": 200,
20
+ "message": "success"
21
+ }
22
+ }
@@ -0,0 +1,20 @@
1
+ {
2
+ "data": {
3
+ "image": {
4
+ "id": "5a44671ab3957c2ab5c33326",
5
+ "answer": null,
6
+ "credit_charged": 0,
7
+ "custom_id": null,
8
+ "data": "https://assets-cdn.github.com/images/modules/open_graph/github-mark.png",
9
+ "instruction": "Instruction",
10
+ "postback_url": "https://9333bbac.ngrok.io/callbacks",
11
+ "processed_at": null,
12
+ "project_id": 102,
13
+ "status": "unprocess"
14
+ }
15
+ },
16
+ "meta": {
17
+ "code": 200,
18
+ "message": "success"
19
+ }
20
+ }
@@ -0,0 +1,22 @@
1
+ {
2
+ "data": {
3
+ "images": [
4
+ {
5
+ "id": "5a44671ab3957c2ab5c33326",
6
+ "answer": [],
7
+ "credit_charged": 0,
8
+ "custom_id": null,
9
+ "data": "https://assets-cdn.github.com/images/modules/open_graph/github-mark.png",
10
+ "instruction": "Instruction",
11
+ "postback_url": "https://9333bbac.ngrok.io/callbacks",
12
+ "processed_at": null,
13
+ "project_id": 102,
14
+ "status": "unprocess"
15
+ }
16
+ ]
17
+ },
18
+ "meta": {
19
+ "code": 200,
20
+ "message": "success"
21
+ }
22
+ }
@@ -0,0 +1,20 @@
1
+ {
2
+ "data": {
3
+ "image": {
4
+ "id": "5a44671ab3957c2ab5c33326",
5
+ "answer": [],
6
+ "credit_charged": 0,
7
+ "custom_id": null,
8
+ "data": "https://assets-cdn.github.com/images/modules/open_graph/github-mark.png",
9
+ "instruction": "Instruction",
10
+ "postback_url": "https://9333bbac.ngrok.io/callbacks",
11
+ "processed_at": null,
12
+ "project_id": 102,
13
+ "status": "unprocess"
14
+ }
15
+ },
16
+ "meta": {
17
+ "code": 200,
18
+ "message": "success"
19
+ }
20
+ }
@@ -0,0 +1,21 @@
1
+ {
2
+ "data": {
3
+ "image": [
4
+ {
5
+ "id": "5a44671ab3957c2ab5c33326",
6
+ "answer": "approved",
7
+ "credit_charged": 0,
8
+ "custom_id": null,
9
+ "data": "https://s3-ap-northeast-1.amazonaws.com/marinchat/uploads/user/6951939/profile_icon/veOSbIBCR.jpg",
10
+ "postback_url": "http://localhost:3000/projects",
11
+ "processed_at": "2017-11-16T10:10:56.282+07:00",
12
+ "project_id": 93,
13
+ "status": "processed"
14
+ }
15
+ ]
16
+ },
17
+ "meta": {
18
+ "code": 200,
19
+ "message": "success"
20
+ }
21
+ }