lanej / cistern Goto Github PK
View Code? Open in Web Editor NEWRuby API client framework
Home Page: http://lanej.io/cistern
License: MIT License
Ruby API client framework
Home Page: http://lanej.io/cistern
License: MIT License
I don't know what this does.
๐ฉ ๐ฉ ๐ฉ ๐ฉ ๐ฉ ๐ฉ ๐ฉ ๐ฉ ๐ฉ ๐ฉ ๐ฉ ๐ฉ
๐ฉ ๐ฉ ๐ฉ ๐ฉ ๐ฉ ๐ฉ ๐ฉ ๐ฉ ๐ฉ ๐ฉ ๐ฉ ๐ฉ
๐ฉ ๐ฉ ๐ฉ ๐ฉ ๐ฉ ๐ฉ ๐ฉ ๐ฉ ๐ฉ ๐ฉ ๐ฉ ๐ฉ
๐ฉ ๐ฉ ๐ฉ ๐ฉ ๐ฉ ๐ฉ ๐ฉ ๐ฉ ๐ฉ ๐ฉ ๐ฉ ๐ฉ
๐ฉ ๐ฉ ๐ฉ ๐ฉ ๐ฉ ๐ฉ ๐ฉ ๐ฉ ๐ฉ ๐ฉ ๐ฉ ๐ฉ
๐ฉ ๐ฉ ๐ฉ ๐ฉ ๐ฉ ๐ฉ ๐ฉ ๐ฉ ๐ฉ ๐ฉ ๐ฉ ๐ฉ
๐ฉ ๐ฉ ๐ฉ ๐ฉ ๐ฉ ๐ฉ ๐ฉ ๐ฉ ๐ฉ ๐ฉ ๐ฉ ๐ฉ
๐ฉ ๐ฉ ๐ฉ ๐ฉ ๐ฉ ๐ฉ ๐ฉ ๐ฉ ๐ฉ ๐ฉ ๐ฉ ๐ฉ
๐ฉ ๐ฉ ๐ฉ ๐ฉ ๐ฉ ๐ฉ ๐ฉ ๐ฉ ๐ฉ ๐ฉ ๐ฉ ๐ฉ
๐ฉ ๐ฉ ๐ฉ ๐ฉ ๐ฉ ๐ฉ ๐ฉ ๐ฉ ๐ฉ ๐ฉ ๐ฉ ๐ฉ
changes to empty string
don't want to write the whole parameters list everytime
like strong parameters
While debugging an application using cistern I needed to run with -d
to determine the cause of a segmentation fault (it was a SystemStackError that overflowed just a bit too much).
However, when looking at the output, I see many repetitions of:
Exception `NoMethodError' at /โฆ/gems/cistern-2.2.3/lib/cistern/attributes.rb:126 - undefined method `+' for nil:NilClass
This is line 126 of attributes.rb and it should use feature detection like the accompanying work over here. Without this a stack trace is generated and destroyed every time an attribute is read (which can be a large object).
all for custom wait for policies.
for example, expontential backoff with max
New syntax described here:
https://github.com/codeclimate/ruby-test-reporter/blob/master/CHANGELOG.md#v100-2016-11-03
The change will also require an update to the default rake task so that it reports to CodeClimate.
I fixed it for #78 with this 3784b63 but that's not a long term solution obviously.
or just remove and provide an awesome_print plugin or something that people can use independently of the core library.
Primary alternative: file-based persistence storage.
Cistern's collection.rb
uses to_set
on BLACKLISTED_ARRAY_METHODS
which is an Array.
However, in Ruby 2.x (http://www.ruby-doc.org/core-2.0/Array.html, http://www.ruby-doc.org/core-2.1.1/Array.html), the to_set
method has been removed.
Be able to use and run cistern in Ruby 2.x which is the default OSX version in Mavericks.
Exception is thrown when using the collections:
/Library/Ruby/Gems/2.0.0/gems/cistern-0.5.3/lib/cistern/collection.rb:9:in `<class:Collection>': undefined method `to_set' for #<Array:0x007f8f4a3220b8> (NoMethodError)
Instantiate a Collections object and invoke BLACKLISTED_ARRAY_METHODS
Due to my restricted knowledge of Ruby and how to best include scripts, I could only test the fix with what I've been given :)
In collections.rb
I've done the following:
require 'set'
class Cistern::Collection
extend Cistern::Attributes::ClassMethods
include Cistern::Attributes::InstanceMethods
BLACKLISTED_ARRAY_METHODS = Set.new [
:compact!, :flatten!, :reject!, :reverse!, :rotate!, :map!,
:shuffle!, :slice!, :sort!, :sort_by!, :delete_if,
:keep_if, :pop, :shift, :delete_at, :compact
] # :nodoc
This appears to fix the issue. Should I make a pull-request with this?
in the gemspec but not required
As in #47 the documentation says identity is "not required" but if you don't have it defined you get an unhelpful error when you call #new_record? on a Model
instance:
$ ruby -e 'gem "cistern", "= 2.0.3"; require "cistern"; class MyService < Cistern::Service; end; p Cistern::VERSION; p MyService::Model.new.new_record?'
"2.0.3"
/โฆ/gems/cistern-2.0.3/lib/cistern/attributes.rb:176:in `identity': nil is not a symbol nor a string (TypeError)
from /โฆ/gems/cistern-2.0.3/lib/cistern/attributes.rb:225:in `new_record?'
from -e:1:in `<main>'
This behavior is new in 2.0.3 and did not exist in 2.0.2:
$ ruby -e 'gem "cistern", "= 2.0.2"; require "cistern"; class MyService < Cistern::Service; end; p Cistern::VERSION; p MyService::Model.new.new_record?'
"2.0.2"
PS
The service we're wrapping has a compound identifier so Cistern::Attributes::identity
is insufficient. I can work around this bug in the mean time, though.
I have the following response format:
{
price: {
amount: 179,
currency: "EUR"
}
}
I would like to have the attributes amount
and currency
, so I tried this
attribute :price, aliases: 'price', squash: 'amount'
attribute :currency, aliases: 'price', squash: 'currency'
Problem is that the alias of the second attribute overwrites the first attribute and the resulting object only has currency
but no price
.
for instance base64 encoded attributes
use symbol registration or classes directly
After https://github.com/lanej/cistern/blob/master/lib/cistern/service.rb#L118 should check if Real has the expected method defined, if not it should error sensibly, so you know that you probably mis-typed the function name
The documentation says identity is "not required" but if you don't have it defined as an attribute you can't inspect a Model
instance:
$ ruby -rcistern -e 'class MyService < Cistern::Service; end; MyService::Model.new.inspect'
/โฆ/gems/cistern-2.0.2/lib/cistern/attributes.rb:176:in `identity': nil is not a symbol nor a string (TypeError)
from /โฆ/gems/cistern-2.0.2/lib/cistern/model.rb:30:in `inspect'
from -e:1:in `<main>'
service
is a common term and can result in namespace conflictscistern
is unique and descriptiveneed to deprecate out service
currently cannot alias has_many
or belongs_to
associations.
Hey there, sorry to be a bother... With the merging of #86 and #87, it seems like it might be worthwhile to cut a new version of the gem to allow updating to Ruby 3 and handling the use case highlighted in #87.
If needed/desired, I could do this if I'm added to https://rubygems.org/gems/cistern My username is the same there as it is here, valarissa, if that's the route you wanted to take.
Totally understand if that's not a desired course of action.
Consider the following
class Blah < Cistern::Model
attribute :fanart, aliases: "Images", squash: "fanart"
attribute :boxart, aliases: "Images", squash: "boxart"
end
When creating this model with a hash of:
{"Images" => {"fanart" => { stuff }, "boxart" => { stuff } }
The boxart attribute will end up with the contents of
{"fanart" => { stuff }, "boxart" => { stuff } }
The last attribute that you squash when you are trying to squash on the same alias more than once, will always end up with the complete squashed hash, earlier defined attributes end up nil.
This would prevent having to create one-off attr_accessor
s for certain actions.
https://www.ruby-lang.org/en/news/2019/12/12/separation-of-positional-and-keyword-arguments-in-ruby-3-0/ seems to be the big issue with this library.
Let's try to upgrade to 3.x.
When loading a collection if you do
cistern.things(page: 1, per_page: 3).each {|thing| thing.call }
the parameters won't get passed through to the all
call that the load_records
method calls.
It works if you call
cistern.things.all(page: 1, per_page: 3).each {|thing| thing.call }
currently changes to 0
return nil if reload was unsuccesful
I really like the cistern approach but a quickstart guide that explains the basic functionalities would be nice.
I'm happy to contribute this once my first API wrapper is done. :)
How do I create/return models or a collection for a request?
I created a request that fetches a list of items (e.g. like this: https://github.com/lanej/zendesk2/blob/master/lib/zendesk2/client/requests/get_tickets.rb) but it returns a Faraday::Response
right now (I use Faraday like the zendesk2 gem). How do I make it return a collection object?
On top of that, the response looks like this:
{
query: "stuff",
items: 10,
accesskey: "123",
operation: "itemsearch",
page: 1
},
items: {
totalresults: 356,
totalpages: 36,
item: [
{
item data
},
...
How can I extract the totalresults
and totalpages
fields as well?
Thanks for a great gem! :)
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.