No commit activity in last 3 years
No release in over 3 years
A set of libraries that supports building an object-oriented ruby SDK on top of a RESTful JSON web service.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Runtime

 Project Readme

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