Class: OpenGraphIO
- Inherits:
-
Object
- Object
- OpenGraphIO
- Defined in:
- lib/opengraph-io.rb
Instance Attribute Summary collapse
-
#app_id ⇒ Object
Returns the value of attribute app_id.
-
#cache_ok ⇒ Object
Returns the value of attribute cache_ok.
-
#full_render ⇒ Object
Returns the value of attribute full_render.
-
#use_proxy ⇒ Object
Returns the value of attribute use_proxy.
-
#version ⇒ Object
Returns the value of attribute version.
Instance Method Summary collapse
- #get_site_info(passed_url, options = {}) ⇒ Object
- #get_site_info_query_params(options) ⇒ Object
- #get_site_info_url(url) ⇒ Object
-
#initialize(options) ⇒ OpenGraphIO
constructor
A new instance of OpenGraphIO.
Constructor Details
#initialize(options) ⇒ OpenGraphIO
Returns a new instance of OpenGraphIO.
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/opengraph-io.rb', line 10 def initialize() # Throw an error if app_id is not present in options hash raise ArgumentError.new( 'app_id must be supplied when making requests to the API. '\ 'Get a free app_id by signing up here: https://www.opengraph.io/' ) unless .has_key?(:app_id) @app_id = [:app_id] # Assign options if present, or defaults if not # These can be overridden when making requests through OpenGraphIO#get_site_info @cache_ok = .has_key?(:cache_ok) ? [:cache_ok] : true @use_proxy = .has_key?(:use_proxy) ? [:use_proxy] : false @full_render = .has_key?(:full_render) ? [:full_render] : false @version = .has_key?(:version) ? [:version] : '1.1' end |
Instance Attribute Details
#app_id ⇒ Object
Returns the value of attribute app_id.
7 8 9 |
# File 'lib/opengraph-io.rb', line 7 def app_id @app_id end |
#cache_ok ⇒ Object
Returns the value of attribute cache_ok.
7 8 9 |
# File 'lib/opengraph-io.rb', line 7 def cache_ok @cache_ok end |
#full_render ⇒ Object
Returns the value of attribute full_render.
7 8 9 |
# File 'lib/opengraph-io.rb', line 7 def full_render @full_render end |
#use_proxy ⇒ Object
Returns the value of attribute use_proxy.
7 8 9 |
# File 'lib/opengraph-io.rb', line 7 def use_proxy @use_proxy end |
#version ⇒ Object
Returns the value of attribute version.
7 8 9 |
# File 'lib/opengraph-io.rb', line 7 def version @version end |
Instance Method Details
#get_site_info(passed_url, options = {}) ⇒ Object
77 78 79 80 81 82 |
# File 'lib/opengraph-io.rb', line 77 def get_site_info(passed_url, = {}) uri = URI(get_site_info_url(passed_url)) uri.query = URI.encode_www_form(get_site_info_query_params()) response = Net::HTTP.get(uri) parsed = JSON.parse(response) end |
#get_site_info_query_params(options) ⇒ Object
46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 |
# File 'lib/opengraph-io.rb', line 46 def get_site_info_query_params() query_string_values = {} query_string_values[:app_id] = .has_key?(:app_id) ? [:app_id] : @app_id query_string_values[:cache_ok] = .has_key?(:cache_ok) ? [:cache_ok] : @cache_ok query_string_values[:use_proxy] = .has_key?(:use_proxy) ? [:use_proxy] : @use_proxy query_string_values[:full_render] = .has_key?(:full_render) ? [:full_render] : @full_render query_string_values[:version] = .has_key?(:version) ? [:version] : @version query_string_values end |
#get_site_info_url(url) ⇒ Object
42 43 44 |
# File 'lib/opengraph-io.rb', line 42 def get_site_info_url(url) 'https://opengraph.io/api/' + @version + '/site/' + CGI.escape(url) end |