Skip to content

[WIP] Add query helpers. #1

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 7 commits into from
Closed

[WIP] Add query helpers. #1

wants to merge 7 commits into from

Conversation

beauby
Copy link
Member

@beauby beauby commented Oct 30, 2016

Example:

The following generates a query http://api.example.com/users/2?include=posts.author,posts.comments.author&fields[posts]=title,content&fields[users]=name,email&page=3 and parses the response (wrapped inside a JSONAPI::Client::Response object, that exposes status, headers and body, body being a JSONAPI::Client::Document instance or nil).

  client = JSONAPI::Client.new(base_url: 'http://api.example.com')

  req = client[:users]
    .include(posts: [:author, comments: [:author]])
    .fields(posts: [:title, :content], users: [:name, :email])
    .params(page: 3)
    .find(2)

  req.to_h
# => {
#  :method=>:get, 
#  :uri=>"http://api.example.com/users/2?include=posts.author,posts.comments.author&fields[posts]=title,content&fields[users]=name,email&page=3", 
#  :base_uri=>"http://api.example.com/users/2", 
#  :data=>nil, 
#  :params=>{
#    :include=>"posts.author,posts.comments.author", 
#    :"fields[posts]"=>"title,content", 
#    :"fields[users]"=>"name,email", 
#    :page=>3
#  }, 
#  :headers=>{
#    :"Content-Type"=>"application/vnd.api+json", 
#    :Accept=>"application/vnd.api+json"
#  }
#}

@beauby beauby changed the title Add query helpers. [WIP] Add query helpers. Oct 30, 2016
@@ -0,0 +1,13 @@
require 'jsonapi/client'

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing frozen string literal comment.


module JSONAPI
class Client
class Response

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing top-level class documentation comment.

@@ -0,0 +1,25 @@
require 'jsonapi/client/document'

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing frozen string literal comment.


private

def request

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Method has too many lines. [17/10]


module JSONAPI
class Client
class Request

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Class has too many lines. [123/100]
Missing top-level class documentation comment.

@@ -0,0 +1,157 @@
require 'net/http'

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing frozen string literal comment.

@@ -1,5 +1,10 @@
require 'jsonapi/client/resource'

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing frozen string literal comment.

@base_url = base_url
@headers = {
:'Content-Type' => 'application/vnd.api+json',
:Accept => 'application/vnd.api+json'

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use the new Ruby 1.9 hash syntax.

def initialize(base_url: nil, headers: {})
@base_url = base_url
@headers = {
:'Content-Type' => 'application/vnd.api+json',

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use the new Ruby 1.9 hash syntax.

require 'jsonapi/client/response'

module JSONAPI
class Client

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing top-level class documentation comment.


module JSONAPI
class Client
class Request

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Class has too many lines. [124/100]
Missing top-level class documentation comment.

response =
Net::HTTP.start(uri.host, use_ssl: uri.scheme == 'https') do |http|
http.request request
end

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

end at 21, 8 is not aligned with Net::HTTP.start(uri.host, use_ssl: uri.scheme == 'https') do |http| at 19, 10.


module JSONAPI
class Client
class Request

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Class has too many lines. [125/100]
Missing top-level class documentation comment.


private

def request

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Method has too many lines. [21/10]


module JSONAPI
class Client
class Request

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Class has too many lines. [129/100]
Missing top-level class documentation comment.

@pcriv
Copy link

pcriv commented Mar 21, 2018

@beauby Is this gem still maintained? :)

@beauby beauby closed this Dec 11, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants