Sha256: 1e1bcb3601f3b19b62e737d227843583c5951411a7e3de234a55e87c192f5f52

Contents?: true

Size: 977 Bytes

Versions: 1

Compression:

Stored size: 977 Bytes

Contents

require "bomb_bomb/version"
require "json"

module BombBomb

  class API
    def initialize(email, pw)
      @email = email
      @pw    = pw
    end

    def call(method, args)
      parsed_response = make_call(method, args)
      parsed_response
    end

    def method_missing(method, *args)
      method = camelize_method(method)
      call(method, args)
    end

    private
    def param_fields(args)
      params          = {}
      params["email"] = @email
      params["pw"]    = @pw
      params          = args.first.merge(params) if args.first
      params
    end

    def make_call(method, args)
      response = Curl.post("https://app.bombbomb.com/app/api/api.php?method=#{method}", param_fields(args))
      JSON.load("[#{response.body_str}]").first
    end

    def camelize_method(method)
      method = method.to_s.gsub(/\/(.?)/) { "::#{$1.upcase}" }.gsub(/(?:^|_)(.)/) { $1.upcase }
      testmethod = method[0].chr.upcase + method[1..-1]
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
bomb_bomb-0.0.2 lib/bomb_bomb.rb