Skip to content
This repository was archived by the owner on Oct 10, 2020. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 3 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,23 +1,13 @@
# doge_api
# doge_papi

## Description
doge_api is a minimal Ruby wrapper for DogeAPI.
doge_papi is a minimal Ruby wrapper for DogeAPI and DogeChain that takes care of parsing the DogeAPI and DogeChain outputs into proper Ruby objects (integers, floats, arrays, etc.), a fork of even more minimal [tekknolagi/doge_api](https://github.com/tekknolagi/doge_api)

## Installation
Just run `gem install doge_api` and you're all set.

If you want to use this as part of a package, just add:
<pre>
gem 'doge_api'
</pre>
to your Gemfile.

## Usage
Check `test.rb` for some examples.

## License
This teeny-tiny project is under the MIT license.

## Badges and things
[![Gem Version](https://badge.fury.io/rb/doge_api.png)](http://badge.fury.io/rb/doge_api)
[![Google Analytics](https://ga-beacon.appspot.com/UA-47678422-2/tekknolagi/doge_api)](https://ga-beacon.appspot.com/)
This project is under the MIT license.
11 changes: 0 additions & 11 deletions doge_api.gemspec

This file was deleted.

44 changes: 31 additions & 13 deletions lib/doge/api.rb
Original file line number Diff line number Diff line change
@@ -1,28 +1,46 @@
require 'uri'
require 'open-uri'

module DogeApi
module DogePapi
class DogeApi
attr_accessor :api_key

def initialize(api_key)
BASE_URI = URI.parse 'https://www.dogeapi.com/wow'

CALLS_RETURNING_INTEGER = [:get_current_block]
CALLS_RETURNING_FLOAT = [
:get_balance ,
:get_address_received ,
:get_difficulty ,
:get_current_price
]
CALLS_RETURNING_JSON = [:get_my_addresses]

def initialize api_key
@api_key = api_key
@base_uri = URI.parse('https://www.dogeapi.com/wow')
end

def build_uri(m, args)
uri = @base_uri
params = args.merge(:a => m, :api_key => @api_key)
uri.query = URI.encode_www_form(params)
def build_uri m, args
uri = BASE_URI
params = args.merge a: m, api_key: @api_key
uri.query = URI.encode_www_form params
uri
end

def fetch_uri(uri)
def fetch_uri uri
uri.open.read
end

def method_missing(m, args = {}, &block)
fetch_uri build_uri(m, args)
def method_missing m, args = {}, &block
output = fetch_uri build_uri(m, args)
if CALLS_RETURNING_JSON.include? m
output = JSON.parse output
else
# Doge API wraps everything in double quotes,
# so we need to get rid of them first.
#
output.tr! '"', ''
output = output.to_i if CALLS_RETURNING_INTEGER.include? m
output = output.to_f if CALLS_RETURNING_FLOAT.include? m
end
output
end
end
end
35 changes: 22 additions & 13 deletions lib/doge/chain.rb
Original file line number Diff line number Diff line change
@@ -1,24 +1,33 @@
require 'uri'
require 'open-uri'

module DogeApi
module DogePapi
class DogeChain
def initialize
@base_uri = 'http://dogechain.info/chain/Dogecoin/q'
end

def build_uri(m, params)
BASE_URI = 'http://dogechain.info/chain/Dogecoin/q'

CALLS_RETURNING_INTEGER = [:getblockcount]
CALLS_RETURNING_FLOAT = [
:addressbalance ,
:getdifficulty ,
:getreceivedbyaddress ,
:getsentbyaddress ,
:totalbc
]
CALLS_RETURNING_JSON = [:transactions]

def build_uri m, params
list = params.join '/'
uri = URI.parse("#{@base_uri}/#{m}/#{list}")
uri
URI.parse "#{BASE_URI}/#{m}/#{list}"
end

def fetch_uri(uri)
def fetch_uri uri
uri.open.read
end

def method_missing(m, *args, &block)
fetch_uri build_uri(m, args)
def method_missing m, *args, &block
output = fetch_uri build_uri(m, args)
output = output.to_i if CALLS_RETURNING_INTEGER.include? m
output = output.to_f if CALLS_RETURNING_FLOAT.include? m
output = JSON.parse(output) if CALLS_RETURNING_JSON.include? m
output
end
end
end
2 changes: 0 additions & 2 deletions lib/doge_api.rb

This file was deleted.

6 changes: 6 additions & 0 deletions lib/doge_papi.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
require 'uri'
require 'open-uri'
require 'json'

require_relative 'doge/api'
require_relative 'doge/chain'
4 changes: 2 additions & 2 deletions test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
$my_address = 'DBv97MSG4gNjcGoHCMX1nfanLjzBgVERi9'
$my_api_address = 'DPf8M6McXUZW5zDxwAKXAfid4A78P8o21M'

doge_api = DogeApi::DogeApi.new($my_api_key)
doge_api = DogePapi::DogeApi.new($my_api_key)
doge_api.get_balance
doge_api.withdraw :amount => 5, :payment_address => $my_address
doge_api.get_new_address :address_label => 'my pretty address'
Expand All @@ -15,7 +15,7 @@
doge_api.get_current_block
doge_api.get_current_price

doge_chain = DogeApi::DogeChain.new
doge_chain = DogePapi::DogeChain.new
doge_chain.addressbalance $my_address
doge_chain.addresstohash $my_address
doge_chain.checkaddress $my_address
Expand Down