postgrest 0.1.0 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: e8867bc92b600721834d706875e5d96805c88f3c7314088c81547e907da741d7
4
- data.tar.gz: c215c962a1d3f530da16bc8d16e34089438f5ee2acef7f551aa76870c60ad6dd
3
+ metadata.gz: 31d776cb72c9cb40561438468b582974966fbff3a1d48923a20f701f98ef61d8
4
+ data.tar.gz: 6461befd87bde10d825c5973a91d070772ba9366e6019fa85815a7c6f0607a98
5
5
  SHA512:
6
- metadata.gz: 49e2357915dd71ce84a784749e98c7d6d0c40f323bc2dafc4b4dc8335518b5e6e3a3af44ba87bf3e881b2f0fd5e498246eef19798999ceb9df9b995990467935
7
- data.tar.gz: 9d169f87f00c70c50a2a058a099c3eed8e5d0f18e185a08df13bea077dca4a9147d64b581977294415419962e33e8739f4c5273cc1673929175fc60d09d6ce7e
6
+ metadata.gz: 3e1296d2329496e118ef1d01a6e8cb198b114a6b9633fb78ee595fc64eedc537321ba546c713ae2f17e23bd4295cdf44a2f73500746c3985f94c235d31c5fb96
7
+ data.tar.gz: 6dbafc5fb71f17e5f6409fee5182c8a85f1f262378e0aeddd47482883f4376f55e64e5ca42e07634730e41df9d551845c6a17e4393d7689de13a9bf0f22dd30e
data/.gitignore CHANGED
@@ -10,4 +10,6 @@
10
10
  # rspec failure tracking
11
11
  .rspec_status
12
12
 
13
- bin/private_console
13
+ bin/private_console
14
+
15
+ *.gem
data/.travis.yml CHANGED
@@ -1,6 +1,15 @@
1
- ---
1
+ env:
2
+ global:
3
+ - CC_TEST_REPORTER_ID=$CODE_CLIMATE_TOKEN
2
4
  language: ruby
3
- cache: bundler
4
5
  rvm:
5
6
  - 2.6.6
6
- before_install: gem install bundler -v 2.1.4
7
+ before_script:
8
+ - curl -L https://codeclimate.com/downloads/test-reporter/test-reporter-latest-linux-amd64 > ./cc-test-reporter
9
+ - chmod +x ./cc-test-reporter
10
+ - ./cc-test-reporter before-build
11
+ - gem install bundler:2.1.4
12
+ script:
13
+ - bundle exec rspec
14
+ after_script:
15
+ - ./cc-test-reporter after-build --exit-code $TRAVIS_TEST_RESULT
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- postgrest (0.1.0)
4
+ postgrest (0.2.0)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
data/README.md CHANGED
@@ -2,11 +2,11 @@
2
2
 
3
3
  ## Status
4
4
 
5
- [![Build Status](https://api.travis-ci.org/marcelobarreto/postgrest.svg?branch=master)](https://travis-ci.org/marcelobarreto/postgrest-rb)
5
+ [![Build Status](https://api.travis-ci.com/marcelobarreto/postgrest-rb.svg?branch=master)](https://travis-ci.com/marcelobarreto/postgrest-rb)
6
6
  [![Code Climate](https://codeclimate.com/github/marcelobarreto/postgrest-rb.svg)](https://codeclimate.com/github/marcelobareto/postgrest-rb)
7
7
  [![Code Climate](https://codeclimate.com/github/marcelobarreto/postgrest-rb/coverage.svg)](https://codeclimate.com/github/marcelobarreto/postgrest-rb)
8
8
  [![Ruby Style Guide](https://img.shields.io/badge/code_style-rubocop-brightgreen.svg)](https://github.com/rubocop/rubocop)
9
- [![RubyGems](http://img.shields.io/gem/dt/postgrest-rb.svg?style=flat)](http://rubygems.org/gems/postgrest-rb)
9
+ [![RubyGems](http://img.shields.io/gem/dt/postgrest.svg?style=flat)](http://rubygems.org/gems/postgrest)
10
10
 
11
11
  Ruby client for [PostgREST](https://postgrest.org/)
12
12
 
@@ -11,33 +11,30 @@ module Postgrest
11
11
  request[key] = value
12
12
  end
13
13
 
14
- headers['Content-Type'] = 'application/json'
14
+ request['Content-Type'] = 'application/json'
15
+
16
+ # count?: null | 'exact' | 'planned' | 'estimated'
17
+ # returning?: 'minimal' | 'representation'
18
+
19
+ prefer = ['return=representation', 'resolution=merge-duplicates', 'count=exact']
20
+ request['Prefer'] = prefer.join(',')
15
21
 
16
22
  nil
17
23
  end
18
24
 
19
25
  def get(uri:, query: {}, headers: {})
20
- res = Net::HTTP.start(uri.hostname, uri.port, use_ssl: true) do |http|
26
+ response = Net::HTTP.start(uri.hostname, uri.port, use_ssl: true) do |http|
21
27
  uri.query = URI.encode_www_form(query)
22
28
  req = Net::HTTP::Get.new(uri)
23
29
  set_request_headers(req, headers)
24
30
  http.request(req)
25
31
  end
26
32
 
27
- data = response_is_successful?(res) ? JSON.parse(res.body) : []
28
-
29
- Response.new({
30
- error: !response_is_successful?(res),
31
- data: data,
32
- count: data.count,
33
- status: res.code.to_i,
34
- status_text: res.message,
35
- body: query
36
- })
33
+ get_response(response: response, body: query)
37
34
  end
38
35
 
39
36
  def post(uri:, body: {}, headers: {})
40
- res = Net::HTTP.start(uri.hostname, uri.port, use_ssl: true) do |http|
37
+ response = Net::HTTP.start(uri.hostname, uri.port, use_ssl: true) do |http|
41
38
  req = Net::HTTP::Post.new(uri)
42
39
  req.body = body.to_json
43
40
  req.content_type = 'application/json'
@@ -45,14 +42,7 @@ module Postgrest
45
42
  http.request(req)
46
43
  end
47
44
 
48
- Response.new({
49
- error: !response_is_successful?(res),
50
- data: res.body,
51
- count: nil,
52
- status: res.code.to_i,
53
- status_text: res.message,
54
- body: body
55
- })
45
+ post_response(response: response, body: body)
56
46
  end
57
47
 
58
48
  private
@@ -60,6 +50,38 @@ module Postgrest
60
50
  def response_is_successful?(response)
61
51
  response.class.ancestors.include?(Net::HTTPSuccess)
62
52
  end
53
+
54
+ def parse_post_response(response)
55
+ return unless response_is_successful?(response)
56
+
57
+ body = response.body.empty? ? '{}' : response.body
58
+
59
+ JSON.parse(body)
60
+ end
61
+
62
+ def get_response(response:, body:)
63
+ data = response_is_successful?(response) ? JSON.parse(response.body) : []
64
+
65
+ Response.new({
66
+ error: !response_is_successful?(response),
67
+ data: data,
68
+ count: data.count,
69
+ status: response.code.to_i,
70
+ status_text: response.message,
71
+ body: body
72
+ })
73
+ end
74
+
75
+ def post_response(response:, body:)
76
+ Response.new({
77
+ error: !response_is_successful?(response),
78
+ data: parse_post_response(response),
79
+ count: nil,
80
+ status: response.code.to_i,
81
+ status_text: response.message,
82
+ body: body
83
+ })
84
+ end
63
85
  end
64
86
  end
65
87
  end
@@ -10,19 +10,18 @@ module Postgrest
10
10
  @schema = schema
11
11
  end
12
12
 
13
- def select(columns = '*')
14
- Postgrest::HTTP.get(uri: uri, query: { select: columns }, headers: headers)
15
- end
16
-
17
- # @client.from('todos').insert([
18
- # { title: 'The Shire', completed: false },
19
- # { title: 'The Shire', completed: false },
20
- # ])
13
+ def select(columns = '*', options = {})
14
+ # @client.from('todos').select('*', { id: 'gt.35' })
21
15
 
22
- # @client.from('todos').insert({ name: 'The Shire', country_id: 554 })
16
+ Postgrest::HTTP.get(uri: uri, query: { select: columns }.merge(options), headers: headers)
17
+ end
23
18
 
24
19
  def insert(values)
25
20
  Postgrest::HTTP.post(uri: uri, body: values, headers: headers)
26
21
  end
22
+
23
+ def update(values); end
24
+
25
+ def match(values); end
27
26
  end
28
27
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Postgrest
4
- VERSION = '0.1.0'
4
+ VERSION = '0.2.0'
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: postgrest
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
  - Marcelo Barreto
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2021-05-01 00:00:00.000000000 Z
11
+ date: 2021-05-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: pry
@@ -113,7 +113,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
113
113
  - !ruby/object:Gem::Version
114
114
  version: '0'
115
115
  requirements: []
116
- rubygems_version: 3.0.3
116
+ rubygems_version: 3.0.9
117
117
  signing_key:
118
118
  specification_version: 4
119
119
  summary: Ruby client for PostgREST