Class: Rubyoverflow::Base

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

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.change_end_point(endpoint) ⇒ Object



61
62
63
# File 'lib/rubyoverflow/base.rb', line 61

def change_end_point(endpoint)
  Client.change_end_point endpoint
end

.clientObject



31
32
33
# File 'lib/rubyoverflow/base.rb', line 31

def client 
  @client ||= Rubyoverflow::Client.config
end

.convert_if_array(id) ⇒ Object



45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
# File 'lib/rubyoverflow/base.rb', line 45

def convert_if_array(id)
  new_id_list = Array.new
  if id.kind_of?(Array)
    id.each do |item|
      if item.respond_to? :item_id
        new_id_list.push item.item_id
      elsif item.kind_of?(String) || item.kind_of?(Integer)
        new_id_list.push item
      end
    end
    return new_id_list.join(';')
  else
    return id
  end
end

.convert_to_id_list(id) ⇒ Object



39
40
41
42
43
# File 'lib/rubyoverflow/base.rb', line 39

def convert_to_id_list(id)
  id = convert_if_array(id)
  id = id.item_id if id.respond_to?(:item_id)
  id.to_s
end

.request(path, parameters = {}) ⇒ Object



35
36
37
# File 'lib/rubyoverflow/base.rb', line 35

def request(path, parameters = {})
  client.request(path, parameters)
end

Instance Method Details

#find_parse_querystring(rawurl) ⇒ Object



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/rubyoverflow/base.rb', line 8

def find_parse_querystring(rawurl)
  queryHash = {}
  if rawurl.include? '?'
  url, querystring = rawurl.split('?')
  
  if querystring
    querystring.split('&').each {|pair|
      key,value=pair.split('=')
      queryHash[key]=value 
    }
    queryHash
  end
  url.sub!(Base.client.host_path,'')
  return url,queryHash
  
  else
  url = rawurl
  end
  url.sub!(Base.client.host_path,'')
  return url,queryHash
end

#request(path, parameters = {}) ⇒ Object



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

def request(path, parameters = {})
  Base.request(path, parameters)
end