Class: Rubyoverflow::Client
- Inherits:
-
Object
- Object
- Rubyoverflow::Client
- Includes:
- HTTParty
- Defined in:
- lib/rubyoverflow.rb
Constant Summary collapse
- HOST =
Most of this class is borrowed from the Pilha (github.com/dlt/pilha) project because a) it works, b) a lot of this code would be the same regardless of implementation (especially the open => gzip code, query string, and normalize), and c) I’m new to ruby, so I’m going to skip pass some of the more ‘boring’ stuff and get to the interesting parts. I plan to re-examine this at a later point
'http://api.stackoverflow.com'
- VERSION =
'1.1'
Instance Attribute Summary collapse
-
#api_key ⇒ Object
readonly
Returns the value of attribute api_key.
-
#host ⇒ Object
readonly
Returns the value of attribute host.
Class Method Summary collapse
- .change_end_point(val = nil) ⇒ Object
-
.config {|options| ... } ⇒ Object
this specifically works well, and I don’t fully understand it, so I borrowed this from Pilha more than anything else If you want to explain why I only have to configure this once than forget about it, please do, because this stuff is currently over my head.
- .init_client!(client) ⇒ Object
- .stackauth_client(api_key = '') ⇒ Object
Instance Method Summary collapse
- #host_path ⇒ Object
-
#initialize(options = OpenStruct.new) ⇒ Client
constructor
A new instance of Client.
- #request(path, parameters) ⇒ Object
Constructor Details
Instance Attribute Details
#api_key ⇒ Object (readonly)
Returns the value of attribute api_key.
61 62 63 |
# File 'lib/rubyoverflow.rb', line 61 def api_key @api_key end |
#host ⇒ Object (readonly)
Returns the value of attribute host.
60 61 62 |
# File 'lib/rubyoverflow.rb', line 60 def host @host end |
Class Method Details
.change_end_point(val = nil) ⇒ Object
95 96 97 98 99 100 101 102 103 104 105 106 107 |
# File 'lib/rubyoverflow.rb', line 95 def change_end_point(val = nil) = OpenStruct.new if val.kind_of? ApiSite .host = val.api_endpoint end if val.kind_of? String .host = val end .api_key = Base.client.api_key init_client! Client.new() end |
.config {|options| ... } ⇒ Object
this specifically works well, and I don’t fully understand it, so I borrowed this from Pilha more than anything else If you want to explain why I only have to configure this once than forget about it, please do, because this stuff is currently over my head
89 90 91 92 93 |
# File 'lib/rubyoverflow.rb', line 89 def config &block = OpenStruct.new yield if block_given? init_client! Client.new() end |
.init_client!(client) ⇒ Object
109 110 111 112 113 114 115 |
# File 'lib/rubyoverflow.rb', line 109 def init_client!(client) base_eigenclass = class << Base; self; end base_eigenclass.send :define_method, :client do @client = client end client end |
Instance Method Details
#host_path ⇒ Object
82 83 84 |
# File 'lib/rubyoverflow.rb', line 82 def host_path normalize(@host) + normalize(@version) end |
#request(path, parameters) ⇒ Object
75 76 77 78 79 80 |
# File 'lib/rubyoverflow.rb', line 75 def request(path, parameters) parameters['key'] = @api_key if @api_key url = host_path + normalize(path) + query_string(parameters) response = self.class.get url return response.parsed_response, url end |