All Projects → rom-rb → Rom Http

rom-rb / Rom Http

Licence: mit
Abstract HTTP adapter for ROM

Programming Languages

ruby
36898 projects - #4 most used programming language

Projects that are alternatives of or similar to Rom Http

Rom Sql
SQL support for rom-rb
Stars: ✭ 169 (+160%)
Mutual labels:  adapter, rubygem
Rom Elasticsearch
Elasticsearch adapter for rom-rb
Stars: ✭ 30 (-53.85%)
Mutual labels:  abstraction, rubygem
Candyview
Implement any RecyclerView in just 1 Line. CandyView handles everything for you.
Stars: ✭ 15 (-76.92%)
Mutual labels:  adapter
Tty Font
Terminal fonts
Stars: ✭ 44 (-32.31%)
Mutual labels:  rubygem
Google Books Android Viewer
Android library to bridge between RecyclerView and sources like web page or database. Includes demonstrator (Google Books viewer)
Stars: ✭ 37 (-43.08%)
Mutual labels:  adapter
Sql Composer
Standalone SQL composer DSL for Ruby
Stars: ✭ 26 (-60%)
Mutual labels:  rubygem
Fastlane Plugin Google drive
fastlane plugin to upload files to Google Drive
Stars: ✭ 39 (-40%)
Mutual labels:  rubygem
Flutter adapter
A plugin that adapts the flutter application to different platforms, allowing your flutter application to flexibly and efficiently adapt to various platforms in the same flutter project, maximizing UI multiplexing, and sharing business logic code across different platforms. Support to select different layout styles in real time according to the screen orientation.
Stars: ✭ 27 (-58.46%)
Mutual labels:  adapter
Spark api
Ruby client library for communication with the Spark API
Stars: ✭ 56 (-13.85%)
Mutual labels:  rubygem
Autogridview
🚥AutoGridView可以更轻松实现QQ空间和微信朋友圈的九宫格、点击展开、点击加号添加照片等功能,而且采用Adapter方式,可以自定义item,更加灵活,使用起来就像ListView和BaseAdapter搭配一样简单...
Stars: ✭ 36 (-44.62%)
Mutual labels:  adapter
Raw Vulkan
🔥 Experiments building Vulkan applications, libraries, and abstractions.
Stars: ✭ 42 (-35.38%)
Mutual labels:  abstraction
Kraken Ruby
Official Ruby Gem for Kraken API
Stars: ✭ 34 (-47.69%)
Mutual labels:  rubygem
Grouprecyclerviewadapter
可增删改查、可动画展开收起、可吸附悬浮动态可配置的分组列表
Stars: ✭ 41 (-36.92%)
Mutual labels:  adapter
Sense Client
Quick and dirty Ruby client for the Hello Sense sleep tracker. Based on http://jeffhuang.com/extracting_my_data_from_the_hello_sense.html
Stars: ✭ 20 (-69.23%)
Mutual labels:  rubygem
Meteorite
一个基于Android MVP的简单明了的指引性通用架构,目的是帮助更多的开发者去全面了解实践开发相关的各种技术,快速搭建属于自已的APP。这个项目涉及到如下技术的实际应用:1、MVP 2、网络请求(Novate基于rxjava,okhttp,retrofit封装架构)3、DbFlow(可保存文件入SD卡) 4、6.0权限申请 5、XRecyclerView 6、万能Adapter7、异常处理 8、日志打印 9、屏幕适配 10、代码混淆 11、多渠道打包 12、内存泄露检测 13、热修复 14、升级更新 15、极光推送 工程更新完善中……欢迎关注 @特别感谢ZJ.Y的Logo支持。
Stars: ✭ 49 (-24.62%)
Mutual labels:  adapter
Human name parser
A name parsing library
Stars: ✭ 7 (-89.23%)
Mutual labels:  rubygem
Fastp
An ultra-fast all-in-one FASTQ preprocessor (QC/adapters/trimming/filtering/splitting/merging...)
Stars: ✭ 966 (+1386.15%)
Mutual labels:  adapter
Flagchatadapter
FlagChatAdapter is easy to implement enchanting recycler view adapter. Just extend your adapter with FlagChatAdapter, impliment some methods and voila! You have got the most beautiful looking chat on your phone. Zero boilerplate code, just put your variables in the right direction.
Stars: ✭ 39 (-40%)
Mutual labels:  adapter
Wireless Rc Adapter
🎮 Arduino USB-Joystick adapter for RC receivers with PWM and PPM modulations up to 8 channels.
Stars: ✭ 62 (-4.62%)
Mutual labels:  adapter
Dry Validation
Validation library with type-safe schemas and rules
Stars: ✭ 1,087 (+1572.31%)
Mutual labels:  rubygem

rom-http Join the chat at https://rom-rb.zulipchat.com

Gem Version Build Status Code Climate Test Coverage Inline docs

HTTP adapter for rom-rb.

Resources:

Installation

Add this line to your application's Gemfile:

gem 'rom-http'

And then execute:

$ bundle

Or install it yourself as:

$ gem install rom-http

Quick-start

require 'rom'

class Users < ROM::Relation[:http]
  schema(:users) do
    attribute :id, ROM::Types::Integer
    attribute :name, ROM::Types::String
    attribute :username, ROM::Types::String
    attribute :email, ROM::Types::String
    attribute :phone, ROM::Types::String
    attribute :website, ROM::Types::String
  end

  def by_id(id)
    with_path(id.to_s)
  end
end

configuration = ROM::Configuration.new(:http, {
  uri: 'http://jsonplaceholder.typicode.com',
  headers: {
    Accept: 'application/json'
  },
  handlers: :json
})

configuration.register_relation(Users)

container = ROM.container(configuration)

container.relation(:users).by_id(1).to_a
# => GET http://jsonplaceholder.typicode.com/users/1 [ Accept: application/json ]

Extending

require 'rom-http'

module ROM
  module MyAdapter
    class Dataset < ROM::HTTP::Dataset
      config.default_request_handler = ->(dataset) do
        uri = dataset.uri

        http = Net::HTTP.new(uri.host, uri.port)
        request_klass = Net::HTTP.const_get(Inflecto.classify(dataset.request_method))

        request = request_klass.new(uri.request_uri)
        
        dataset.headers.each_with_object(request) do |(header, value), request|
          request[header.to_s] = value
        end

        response = http.request(request)
      end

      config.default_response_handler = ->(response, dataset) do
        if %i(post put patch).include?(dataset.request_method)
          JSON.parse(response.body, symbolize_names: true)
        else
          Array([JSON.parse(response.body, symbolize_names: true)]).flatten
        end
      end
    end

    class Gateway < ROM::HTTP::Gateway; end

    class Relation < ROM::HTTP::Relation
      adapter :my_adapter
    end

    module Commands
      class Create < ROM::HTTP::Commands::Create
        adapter :my_adapter
      end

      class Update < ROM::HTTP::Commands::Update
        adapter :my_adapter
      end

      class Delete < ROM::HTTP::Commands::Delete
        adapter :my_adapter
      end
    end
  end
end

ROM.register_adapter(:my_adapter, ROM::MyAdapter)

configuration = ROM::Configuration.new(:my_adapter, {
  uri: 'http://jsonplaceholder.typicode.com',
  headers: {
    Accept: 'application/json'
  }
})

class Users < ROM::Relation[:my_adapter]
  schema(:users) do
    attribute :id, ROM::Types::Integer
    attribute :name, ROM::Types::String
    attribute :username, ROM::Types::String
    attribute :email, ROM::Types::String
    attribute :phone, ROM::Types::String
    attribute :website, ROM::Types::String
  end

  def by_id(id)
    with_path(id.to_s)
  end
end

configuration.register_relation(Users)

container = ROM.container(configuration)

container.relation(:users).by_id(1).to_a
# => GET http://jsonplaceholder.typicode.com/users/1 [ Accept: application/json ]

License

See LICENSE file.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].