Class: SI::CopyscapeAPI

Inherits:
Object
  • Object
show all
Defined in:
lib/copyscape_api.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(username:, api_key:, api_url:) ⇒ CopyscapeAPI

Returns a new instance of CopyscapeAPI.



6
7
8
9
10
# File 'lib/copyscape_api.rb', line 6

def initialize username:, api_key:, api_url:
  @username ||= username
  @api_key ||= api_key
  @api_url ||= api_url
end

Instance Attribute Details

#api_keyObject (readonly)

Returns the value of attribute api_key.



4
5
6
# File 'lib/copyscape_api.rb', line 4

def api_key
  @api_key
end

#api_urlObject (readonly)

Returns the value of attribute api_url.



4
5
6
# File 'lib/copyscape_api.rb', line 4

def api_url
  @api_url
end

#responseObject (readonly)

Returns the value of attribute response.



4
5
6
# File 'lib/copyscape_api.rb', line 4

def response
  @response
end

#usernameObject (readonly)

Returns the value of attribute username.



4
5
6
# File 'lib/copyscape_api.rb', line 4

def username
  @username
end

Instance Method Details

#request(operation:, params: {}, postdata: nil) ⇒ Object



12
13
14
15
16
17
# File 'lib/copyscape_api.rb', line 12

def request operation:, params: {}, postdata: nil
  uri_hash = { u: username, k: api_key, o: operation }
  uri_string = api_url + '?' + params.merge(uri_hash).map{|k,v| "#{k}=#{v}"}.join('&')
  uri = URI.parse(URI.encode(uri_string))
  @response = _respond_to _call_api(uri, postdata)
end