hair-api-client 0.1.0 → 0.2.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: cad2ae82172f0cd1d17f6f7a0852c76bb0c2b201
4
- data.tar.gz: 6028ec25228d5010933d4fe8a0e4ea243ccd2caf
3
+ metadata.gz: 34e9613879e52842f022bd1e3e450054e53273b5
4
+ data.tar.gz: a48f8886576ca9951c83167996c996f8d7541ecd
5
5
  SHA512:
6
- metadata.gz: dbd10a4a0195b97d24ac7c2d7c22fbc3ab42a6d2fe7169df7f929690619eb5571cf02d62fc4b033d7be7438d564e6f8f1bca24c8e3d70dd9f554ba7d918dae94
7
- data.tar.gz: 0606b5a7bed665112e2294664165ce8e3181cdc7d40956e68988d43c31d4bc17649efa90fe62c8b35414b3bfc93f79e8c54eb0062a5448e078b75e2c68005b4c
6
+ metadata.gz: ccdb7efd6435f7b1cd8b13a616d7b4c7c42f36e0ad3611eabc77653c7df5a10af2998a6f016189b4ccd273f601ca77baf555d8c9cf72cd9218198e5f1f07eb70
7
+ data.tar.gz: 5ac80636c1a508f85ba0533ad45bc544b2086feb5721c01d935ebfb4f3c2a2ec3247abe214fdf5509e6ee71b824d74b77b20de54fc40aa43f62128aa4a8c364a
data/README.md CHANGED
@@ -34,6 +34,7 @@ Hair::Api::Client.configure do |options|
34
34
  end
35
35
 
36
36
  res = Hair::Api::Client.image_search('ponytail', {sort: 'asc'})
37
+ res = Hair::Api::Client.record('xxxxxxxxxx', 'title', 'https://www.example.com/', Time.now)
37
38
  ```
38
39
 
39
40
  ## Development
@@ -12,7 +12,9 @@ module Hair
12
12
 
13
13
  API_ENDPOINT = 'https://api.hair.cm'
14
14
 
15
- @@options = {}
15
+ @@options = {
16
+ method: 'get'
17
+ }
16
18
 
17
19
  # Default search options
18
20
  def self.options
@@ -29,16 +31,28 @@ module Hair
29
31
  yield @@options
30
32
  end
31
33
 
34
+ # Search image by query
32
35
  def self.image_search(query, opts = {})
33
36
  opts[:path] = '/image/search'
34
37
  opts[:query] = query
35
38
  self.send_request(opts)
36
39
  end
37
40
 
41
+ # Record status of use
42
+ # key is 10 characters, published_at is Time object.
43
+ def self.record(key, title, url, published_at, opts = {})
44
+ opts[:method] = 'post'
45
+ opts[:path] = '/record'
46
+ opts[:image_key] = key
47
+ opts[:entry_title] = title
48
+ opts[:entry_url] = url
49
+ opts[:approve_date] = published_at.strftime('%Y-%m-%d')
50
+ self.send_request(opts)
51
+ end
52
+
38
53
  def self.send_request(opts)
39
54
  opts = self.options.merge(opts) if self.options
40
- request_url = prepare_url(opts)
41
- http_response = Net::HTTP.get_response(URI::parse(request_url))
55
+ http_response = call_api(opts)
42
56
  res = Response.new(http_response.body)
43
57
  unless http_response.kind_of? Net::HTTPSuccess
44
58
  err_msg = "HTTP Response: #{http_response.code} #{http_response.message}"
@@ -74,9 +88,21 @@ module Hair
74
88
 
75
89
  private
76
90
 
91
+ def self.call_api(opts)
92
+ http_method = opts.delete(:method)
93
+ if http_method == 'post'
94
+ request_url = prepare_url({path: opts.delete(:path)})
95
+ Net::HTTP.post_form(URI::parse(request_url), opts)
96
+ else
97
+ request_url = prepare_url(opts)
98
+ Net::HTTP.get_response(URI::parse(request_url))
99
+ end
100
+ end
101
+
77
102
  def self.prepare_url(opts)
78
103
  path = opts.delete(:path)
79
- API_ENDPOINT + path + '?' + URI.encode_www_form(opts)
104
+ query_string = opts.empty? ? '' : '?' + URI.encode_www_form(opts)
105
+ API_ENDPOINT + path + query_string
80
106
  end
81
107
 
82
108
  end
@@ -1,7 +1,7 @@
1
1
  module Hair
2
2
  module Api
3
3
  module Client
4
- VERSION = "0.1.0"
4
+ VERSION = "0.2.0"
5
5
  end
6
6
  end
7
7
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: hair-api-client
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Takayuki Hasegawa
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2016-12-15 00:00:00.000000000 Z
11
+ date: 2016-12-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler