Git Product home page Git Product logo

simple_sdk_builder's Introduction

Simple SDK Builder

A set of libraries that make it easy to build an SDK gem on top of an HTTP web service.

Currently, only RESTful JSON services are supported.

Synopsis:

class MyNotFoundError < StandardError
  def initialize(response)
    super "object not found: #{response.body}"
  end
end

class MyUnknownError < StandardError; end

class MyBaseClass
  include SimpleSDKBuilder::Base

  config :service_url => 'https://api.davidmdawson.com'
  config :timeout => 15000
  config :error_handlers => {
    '404' => MyNotFoundError,
    '*' => MyUnknownError
  }

end

class MyResource < MyBaseClass
  include SimpleSDKBuilder::Resource

  simple_sdk_attribute :id, :name, :value

  class << self

    def all
      response = json_request( :path => "/my_resources" )
      response.build(MyResource)
    end

    def find(id)
      response = json_request( :path => "/my_resources/#{id}" )
      response.build(MyResource)
    end

  end

  def create
    response = json_request( :path => "/my_resources", :method => :post, :body => self )
    self.attributes = response.parsed_body
    self
  end

  def update(attrs)
    response = json_request( :path => "/my_resources/#{id}", :method => :put, :body => attrs )
    self.attributes = response.parsed_body
    self
  end

  def destroy
    json_request( :path => "/my_resources/#{id}", :method => :delete )
    # leaves current object alone
  end

end

all_resources = MyResource.all
some_resource = MyResource.find(1)
new_resource = MyResource.new( :name => 'test', :value => 'this is a test' ).create
new_resource.update( :value => 'this test is almost done...' )
new_resource.destroy

simple_sdk_builder's People

Contributors

daws avatar

Stargazers

 avatar

Watchers

James Cloos avatar  avatar

Forkers

alexwaffleman

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.