GithubHelp home page GithubHelp logo

lanej / cistern Goto Github PK

View Code? Open in Web Editor NEW
83.0 83.0 17.0 396 KB

Ruby API client framework

Home Page: http://lanej.io/cistern

License: MIT License

Ruby 100.00%
api-client backend cistern mock-data persistence reader ruby singular-resources tolerant-parser writer

cistern's Introduction

Hello, I'm Josh Lane! ๐Ÿ‘‹

Welcome to my GitHub page!

About Me

Also known by my nicknames "lanejoshlane" and "Fast Lane", I'm a Platform Engineering Director with a rich background in tech and leadership. Based in Oakland, CA, I've had an impactful journey through companies like EasyPost, Fastly, Engine Yard. From Maine, I cut my teeth in the Boston technology scene at EMC, HubSpot and Brontes3D (now part of 3M). I hold a profound interest in building robust technology solutions and developing agile, effective teams.

What I Do

๐Ÿš€ Leadership: Steering platform engineering at a logistics technology startup, focusing on creating scalable and efficient software architectures. ๐Ÿ”ง Technologies I'm Passionate About:

  • Rust: Delving deep into its systems programming capabilities, high performance services and stable tools.
  • Ruby: Building APIs and software solutions with an elegant language.
  • Lua: Exploring its simplicity and effectiveness in embedded systems, largely through neovim.

๐ŸŒฑ Iโ€™m currently learning:

  • Advanced Rust programming techniques and best practices.
  • Lua, focusing on its integration with larger systems for better performance.

Projects

  • dotfiles: My configuration settings for Arch, CentOS, and Darwin. (Frequent updates, stability may vary)
  • cistern: Ruby API client framework. An early attempt to create an RPC-like interface for any API that encourages testability.
  • fog-aws: AWS module for the 'fog' Ruby gem. I've largely stepped back from this.
  • zendesk2: A Zendesk API V2 client using Cistern.

Sponsorship

๐ŸŒŸ neovim: I am a proud sponsor of neovim, supporting the advancement of this vital open source project.

Connect with Me

Feel free to explore my repositories and don't hesitate to reach out if you want to talk tech, discuss potential collaborations, or just say hi!

cistern's People

Contributors

alenia avatar gitter-badger avatar gschorkopf avatar jaw6 avatar jhsu avatar jlindley avatar lanej avatar leklund avatar manuelmeurer avatar ryansouza avatar shaiguitar avatar thommahoney avatar valarissa avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

cistern's Issues

Ruby 2.x Array#to_set removed

Description

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.

Expected Behaviour

Be able to use and run cistern in Ruby 2.x which is the default OSX version in Mavericks.

Actual Behaviour

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)

How to reproduce

Instantiate a Collections object and invoke BLACKLISTED_ARRAY_METHODS

Possible Fix

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?

New version of the gem?

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.

Cistern::Model#new_record? raises TypeError when @identity is not set with 2.0.3

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.

Can't squash on multiple fields

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.

Create models/collection from request

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! :)

rename `service` to `cistern`

  • service is a common term and can result in namespace conflicts
  • cistern is unique and descriptive

need to deprecate out service

write a gem description

I don't know what this does.
๐Ÿ’ฉ ๐Ÿ’ฉ ๐Ÿ’ฉ ๐Ÿ’ฉ ๐Ÿ’ฉ ๐Ÿ’ฉ ๐Ÿ’ฉ ๐Ÿ’ฉ ๐Ÿ’ฉ ๐Ÿ’ฉ ๐Ÿ’ฉ ๐Ÿ’ฉ
๐Ÿ’ฉ ๐Ÿ’ฉ ๐Ÿ’ฉ ๐Ÿ’ฉ ๐Ÿ’ฉ ๐Ÿ’ฉ ๐Ÿ’ฉ ๐Ÿ’ฉ ๐Ÿ’ฉ ๐Ÿ’ฉ ๐Ÿ’ฉ ๐Ÿ’ฉ
๐Ÿ’ฉ ๐Ÿ’ฉ ๐Ÿ’ฉ ๐Ÿ’ฉ ๐Ÿ’ฉ ๐Ÿ’ฉ ๐Ÿ’ฉ ๐Ÿ’ฉ ๐Ÿ’ฉ ๐Ÿ’ฉ ๐Ÿ’ฉ ๐Ÿ’ฉ
๐Ÿ’ฉ ๐Ÿ’ฉ ๐Ÿ’ฉ ๐Ÿ’ฉ ๐Ÿ’ฉ ๐Ÿ’ฉ ๐Ÿ’ฉ ๐Ÿ’ฉ ๐Ÿ’ฉ ๐Ÿ’ฉ ๐Ÿ’ฉ ๐Ÿ’ฉ
๐Ÿ’ฉ ๐Ÿ’ฉ ๐Ÿ’ฉ ๐Ÿ’ฉ ๐Ÿ’ฉ ๐Ÿ’ฉ ๐Ÿ’ฉ ๐Ÿ’ฉ ๐Ÿ’ฉ ๐Ÿ’ฉ ๐Ÿ’ฉ ๐Ÿ’ฉ
๐Ÿ’ฉ ๐Ÿ’ฉ ๐Ÿ’ฉ ๐Ÿ’ฉ ๐Ÿ’ฉ ๐Ÿ’ฉ ๐Ÿ’ฉ ๐Ÿ’ฉ ๐Ÿ’ฉ ๐Ÿ’ฉ ๐Ÿ’ฉ ๐Ÿ’ฉ
๐Ÿ’ฉ ๐Ÿ’ฉ ๐Ÿ’ฉ ๐Ÿ’ฉ ๐Ÿ’ฉ ๐Ÿ’ฉ ๐Ÿ’ฉ ๐Ÿ’ฉ ๐Ÿ’ฉ ๐Ÿ’ฉ ๐Ÿ’ฉ ๐Ÿ’ฉ
๐Ÿ’ฉ ๐Ÿ’ฉ ๐Ÿ’ฉ ๐Ÿ’ฉ ๐Ÿ’ฉ ๐Ÿ’ฉ ๐Ÿ’ฉ ๐Ÿ’ฉ ๐Ÿ’ฉ ๐Ÿ’ฉ ๐Ÿ’ฉ ๐Ÿ’ฉ
๐Ÿ’ฉ ๐Ÿ’ฉ ๐Ÿ’ฉ ๐Ÿ’ฉ ๐Ÿ’ฉ ๐Ÿ’ฉ ๐Ÿ’ฉ ๐Ÿ’ฉ ๐Ÿ’ฉ ๐Ÿ’ฉ ๐Ÿ’ฉ ๐Ÿ’ฉ
๐Ÿ’ฉ ๐Ÿ’ฉ ๐Ÿ’ฉ ๐Ÿ’ฉ ๐Ÿ’ฉ ๐Ÿ’ฉ ๐Ÿ’ฉ ๐Ÿ’ฉ ๐Ÿ’ฉ ๐Ÿ’ฉ ๐Ÿ’ฉ ๐Ÿ’ฉ

Cistern::Model#inspect raises TypeError when @identity is not defined

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>'

collection method `load_records` should pass parameters

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 }

Optional coverage feature creates too many NoMethodErrors

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).

Two attributes with the same alias

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.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.