Module: Captchatrader::API

Extended by:
API
Included in:
API
Defined in:
lib/captchatrader/api.rb,
lib/captchatrader/error.rb,
lib/captchatrader/submission.rb

Defined Under Namespace

Classes: Error, Submission

Constant Summary collapse

BASE_URL =
"http://api.captchatrader.com"
SUBMIT_TYPES =
[:url, :file]

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#api_keyObject

Returns the value of attribute api_key.



8
9
10
# File 'lib/captchatrader/api.rb', line 8

def api_key
  @api_key
end

#passwordObject

Returns the value of attribute password.



8
9
10
# File 'lib/captchatrader/api.rb', line 8

def password
  @password
end

#usernameObject

Returns the value of attribute username.



8
9
10
# File 'lib/captchatrader/api.rb', line 8

def username
  @username
end

Instance Method Details

#creditsObject



37
38
39
40
# File 'lib/captchatrader/api.rb', line 37

def credits
  response = get("#{BASE_URL}/get_credits/username:#{API.username}/password:#{API.password}/")
  parse_response(response, :credits)
end

#respond(ticket, correct) ⇒ Object



26
27
28
29
30
31
32
33
34
35
# File 'lib/captchatrader/api.rb', line 26

def respond(ticket, correct)
  params = {
    :ticket     => ticket,
    :is_correct => correct,
    :username   => API.username,
    :password   => API.password
  }
  response = post("#{BASE_URL}/respond", params)
  parse_response(response, :respond)
end

#submit(image, type, match = nil) ⇒ Object

Raises:

  • (ArgumentError)


10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/captchatrader/api.rb', line 10

def submit(image, type, match = nil)
  raise ArgumentError, "type must be one of #{SUBMIT_TYPES.join(', ')}" unless SUBMIT_TYPES.include?(type.to_sym)

  params = {
    :value    => image,
    :type     => type,
    :api_key  => API.api_key,
    :username => API.username,
    :password => API.password
  }
  params[:match] = match if match
  
  response = post("#{BASE_URL}/submit", params)
  parse_response(response, :submit, :image => image)
end