Last active
December 20, 2015 12:19
-
-
Save baya/6129978 to your computer and use it in GitHub Desktop.
Dig for debug api
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'dig' | |
# Dig.set :host, 'localhost:3000' | |
# Dig.set :host, 'fchk.dev' | |
namespace :api do | |
task :get_user_bio => :environment do | |
res = Dig.get 'getUserBio', user_sn: 'ddd' | |
puts res | |
end | |
task :login => :environment do | |
res = Dig.post 'login', login_item: 'mobile', login_value: '13520004618', pwd: '111111' | |
puts res | |
end | |
task :user_info => :environment do | |
res = Dig.get 'userInfo', user_sn: '52b70104-dc78-4a48-bc07-925848deef2b' | |
puts res | |
end | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module Dig | |
class << self | |
MetaG = self | |
def set(attr, value) | |
MetaG.class_eval { attr_reader attr } | |
instance_variable_set "@#{attr}", value | |
end | |
def get(api, params) | |
Dig::Get api: api, params: params | |
end | |
def post(api, params) | |
Dig::Post api: api, params: params | |
end | |
end | |
class Request < Dun::Activity | |
data_reader :api, :params | |
def uri | |
"http://#{Dig.host}/#{api}" | |
end | |
end | |
class Get < Request | |
def call | |
RestClient.get uri, params: params | |
end | |
end | |
class Post < Request | |
def call | |
RestClient.post uri, params | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment