Questions tagged [grape-entity]

grape-entity - Entities - a simple Facade to use with your models and API - extracted from Grape.

grape-entity - Entities - a simple Facade to use with your models and API - extracted from Grape.

https://github.com/intridea/grape-entity

51 questions
1
vote
0 answers

GRAPE-ENTITY ARRAYS

I'm using Grape and Grape-Entity library in Ruby on Rails Project to expose my params from backend. Is any possibility to expose two params values in one entity param? My backend json: {value: '1', value_second: '2'}, but i want to get {values:…
Rafonix
  • 159
  • 1
  • 12
1
vote
1 answer

User Grape Entity with Arrays

I was wondering whether Grape Entity would work for rendering arrays of hashes, I thought I remebered it worked but somehow I cannot get it to work right now, am I doing some obvious mistake? Here's my Entity: class V1::Entities::Searchresult <…
Tom
  • 3,807
  • 4
  • 33
  • 58
1
vote
1 answer

grape-entity represent not working

I am using grape gem for API and grape-entity to generate responses. Simple show/get request is responding fine like returning only data from ActiveRecord Object. Fine When i try to include data from has_many relation it return all the data related…
Abdul Baig
  • 3,683
  • 3
  • 21
  • 48
1
vote
1 answer

Two files requiring each other in ruby

I'm building a web API with Ruby and Grape. I have two classes that requires each other which leads to a situation where I get uninitialized constant class errors. The place where I get the error is in the Entity class for Connector, see the example…
Abris
  • 1,451
  • 3
  • 18
  • 38
1
vote
1 answer

Rails, Grape entity. Expose on condition

I have created grape entity: class VehicleDetails < Grape::Entity expose :id expose :name expose :type expose :health, if: {type: 'basis'} end I want to expose :health if current :type is equal to basis. I try to access it by this method: …
Mr.D
  • 7,353
  • 13
  • 60
  • 119
1
vote
1 answer

Presenting `belongs_to` association via Grape Entity in Rails 4

Given these 2 models: class Conversation < ActiveRecord::Base has_many :messages, :class_name => 'Message', inverse_of: 'conversation' class Entity < Grape::Entity expose :id, :title expose :messages, :using => 'Message::Entity' …
1
vote
1 answer

Grape Rails RSpec test returning 400

I am trying to test my Grape API, but I am receiving a 400 error in my tests, but when I run the action the test is supposed to test, I get a 201 HTTP response as expected. Not sure what is going on here. Below is the specific RSpec test, but you…
maclover7
  • 137
  • 1
  • 11
1
vote
2 answers

How can I do request tests with Grape Entity?

The response body is return the "formated json with Grape Entity", but the first_prefered is returning the complete object (json format). How Can I convert the first_prefered object just to get the exposed fields using grape…
Ivan Santos
  • 626
  • 2
  • 7
  • 19
1
vote
1 answer

Serialize payload into a grape entity on post/put

Is there a way with Grape & Grape-Entity to automatically serialize data into an entity? It seems like all of the examples use params[:var] (from: https://github.com/intridea/grape) desc "Create a status." params do requires :status, type: String,…
Prescott
  • 7,312
  • 5
  • 49
  • 70
0
votes
0 answers

How to expose decorator attributes in Grape Entity

I'm working on exposing some data to a mobile client through the API. Some of that data is defined in a decorator. app/decorators/customer_opportunity_decorator.rb def potential_savings return 'N/A' if opportunity.nil? multiplier =…
jordan
  • 9,570
  • 9
  • 43
  • 78
0
votes
1 answer

Convert input sequence of array of hashes in and represent via grape entity

This is a 2 part question A newbie to activerecord/Rails. Once I execute the below activerecord query, I get results = A.joins(:b).group(:id, :status).count this result, now I want to present the results using an entity by postprocessing the output…
MrKickass
  • 93
  • 1
  • 13
0
votes
1 answer

How do I override the root key in a Grape API response payload?

module Entities class StuffEntity < Grape::Entity root 'stuffs', 'stuff' ... How can I DRY up my code by reusing this entity while still having the flexibility to rename the root keys ('stuffs' and 'stuff') defined in the entity? I might…
Allison
  • 1,925
  • 1
  • 18
  • 25
0
votes
2 answers

ruby grape entity - inheritance, the son does not contain the parent's fields

I would expect to get json with both the name and note fields. But I only get the note field. What am I doing wrong? class OrderPage module Entities class AsSeller < OrderPage::Entities::Order expose :note def note …
0
votes
2 answers

Rails Grape api: performannce when getting more data

i'm facing performance issue using grape api. i have following models: class Profile has_many :transitive_user_profiles end class TransitiveUserProfile < ApplicationRecord belongs_to :profile belongs_to :user belongs_to :client end class…
Siddu hadapad
  • 3,023
  • 5
  • 15
  • 26
0
votes
1 answer

How to fix "undefined method `key?'" in Rails with Grape

I'm creating an API with Ruby on Rails. I use the gem 'grape' to provide the api to the consumer and 'spyke' to receive data from another api. I manipulate and enrich the data I receive from spyke and then pass it on to grape. The problem is, that I…
jobs
  • 63
  • 1
  • 11