6px 0.0.1 → 1.0.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.
Files changed (4) hide show
  1. checksums.yaml +4 -4
  2. data/lib/6px.rb +1 -1
  3. data/lib/6px/client.rb +106 -20
  4. metadata +1 -1
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 8448153968fead44cd21f3249f158e18f6073b07
4
- data.tar.gz: 62b527644776a007bea8b755422ceba78be49b30
3
+ metadata.gz: 3a24925555b5af31ab2a95c19b40b3cacda0f529
4
+ data.tar.gz: 0691e0b3027586c2945ce2336cd21422f1ef3995
5
5
  SHA512:
6
- metadata.gz: 1f71105dd955335742b01b005d1812e2fc885fd11c45446f11d285f336d248aef414a43cff39b92fbeb12b412b5e754d68ef5d459b1df05df12eefcb13394fc1
7
- data.tar.gz: b84a433ac38fd46114336d8ea0f440ab2a7b4a74a7ec6b0f250b984121ef932665e80f487f9419a332f74dcc07969e78b484ff0837471afc4b2162f1787915b0
6
+ metadata.gz: 42d6211294c698e54ac9f7d213cecf771ec9436d1d606f75ba0edf3c779883b4e38292c9b5390ea3b7c8361692aa4a457305b09e24cb57b79b0fde61a9df4f95
7
+ data.tar.gz: dc25ebd34888fffe67ab132357bbe08e794da547619216acf118c3b16d1dd7803e03ef59ce166a8e960a55e2bc5b52b42c5724b2bc5e3e4b23e6d1f833fe7d9b
data/lib/6px.rb CHANGED
@@ -1,4 +1,4 @@
1
1
  require 'httparty'
2
2
  require 'json'
3
3
 
4
- require 'six_px/client'
4
+ require '6px/client'
@@ -1,7 +1,10 @@
1
- class SixPX
1
+ require 'json'
2
2
 
3
+ class SixPX
3
4
  include HTTParty
4
5
 
6
+ METHOD_NAMES = [:rotate, :resize, :crop, :filter, :layer, :analyze]
7
+
5
8
  base_uri 'https://api.6px.io/v1/'
6
9
  headers 'Content-Type' => 'application/json'
7
10
 
@@ -12,39 +15,122 @@ class SixPX
12
15
  api_secret = args[:api_secret]
13
16
  self.class.base_uri << "/users/#{user_id}/"
14
17
  self.class.default_params key: api_key, secret: api_secret
18
+ @payload = {}
19
+ @inputs = {}
20
+ @methods = []
21
+ @refs = {}
22
+ @type = 'jpeg'
23
+ @url = ''
24
+ @data = {}
25
+ @callback = ''
15
26
  end
16
27
 
17
-
28
+ # For querying what jobs have been submitted
18
29
  def jobs(*query)
19
- response = self.class.get("jobs", query: query.first)
20
- ap JSON.parse(response.body)
21
- return JSON.parse(response.body)
30
+ query = query.first
31
+ job_id = query.delete(:job_id) if query
32
+ url = job_id ? "jobs/#{job_id}" : "jobs"
33
+ query = clean_up_search_params(query)
34
+ response = self.class.get(url, query: query).body
35
+ JSON.parse(response)
36
+ end
37
+
38
+ # Sets images to that need to be processed
39
+ def inputs(inputs)
40
+ @inputs = inputs
41
+ self
42
+ end
43
+
44
+ # Add whichs images to process
45
+ def refs(refs)
46
+ @refs = refs
47
+ self
48
+ end
49
+
50
+ # Sets what type the output should be in. Default is jpeg.
51
+ def type(type)
52
+ @type = type
53
+ self
54
+ end
55
+
56
+ # Sets output url
57
+ def url(url)
58
+ @url = url
59
+ self
22
60
  end
23
61
 
24
- def process_images(inputs, methods, output_format='jpeg', destination="")
25
- payload = build_payload(inputs, methods, output_format, destination)
62
+ # Sets additional data on job
63
+ def data(data)
64
+ @data = data
65
+ self
66
+ end
67
+
68
+ # Sets callbacks on job
69
+ def callback(callback)
70
+ @callback = callback
71
+ self
72
+ end
26
73
 
27
- self.class.post("jobs", body: payload.to_json)
74
+ # Defines all functions for methods
75
+ METHOD_NAMES.each do |mn|
76
+ define_method(mn) do |params|
77
+ add_method(mn.to_s, params)
78
+ self
79
+ end
80
+ end
81
+
82
+ # Builds and sends the payload to 6px
83
+ def send
84
+ payload = build_payload.to_json
85
+ empty_variables
86
+ response = self.class.post("jobs", body: payload).body
87
+ JSON.parse(response)
28
88
  end
29
89
 
30
90
  private
31
91
 
32
- def build_payload(inputs, methods, output_format, destination)
92
+ def clean_up_search_params(params)
93
+ parsed_hash = {}
94
+ params.each {|i,k| parsed_hash[i.to_s.gsub('_', '.')] = k }
95
+ parsed_hash
96
+ end
97
+
98
+ # Add methods to method hash
99
+ def add_method(method, options)
100
+ @methods << {
101
+ 'method' => method,
102
+ 'options' => options
103
+ }
104
+ end
105
+
106
+ # Builds the final payload to send
107
+ def build_payload
33
108
  {
34
- input: inputs,
109
+ input: @inputs,
35
110
  output: [
36
111
  {
37
- methods: methods,
38
- type: "image/#{output_format}",
39
- ref: {
40
- 'img1' => false,
41
- 'img2' => false,
42
- 'img3' => false,
43
- 'img4' => false
44
- },
45
- url: destination
112
+ methods: @methods,
113
+ type: "image/#{@type}",
114
+ ref: @refs,
115
+ url: @url
46
116
  }
47
- ]
117
+ ],
118
+ data: @data,
119
+ callback: {
120
+ url: @callback
121
+ }
48
122
  }
49
123
  end
124
+
125
+ # Resets instance variables after request is sent
126
+ def empty_variables
127
+ @payload = {}
128
+ @inputs = {}
129
+ @methods = []
130
+ @refs = {}
131
+ @type = 'jpeg'
132
+ @url = ''
133
+ @data = {}
134
+ @callback = ''
135
+ end
50
136
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: 6px
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 1.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Nick Quaranto