Class: Garapon::API
- Inherits:
-
Object
- Object
- Garapon::API
- Defined in:
- lib/garapon/api.rb
Instance Method Summary collapse
- #channel_list ⇒ Object
-
#initialize(opts = {}) ⇒ API
constructor
A new instance of API.
- #search(condition) ⇒ Object
Constructor Details
#initialize(opts = {}) ⇒ API
Returns a new instance of API.
7 8 9 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 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/garapon/api.rb', line 7 def initialize(opts = {}) [:user, :md5passwd, :dev_id].each do |key| if opts.has_key?(key) == false raise "Error: '#{key}' is not found." end case key when :user @user_id = opts[key] when :md5passwd @passwd = opts[key] when :dev_id @developer_id = opts[key] end end url = 'http://garagw.garapon.info/getgtvaddress' client = HTTPClient.new res = client.post_content(url, opts) res.each_line do |line| key, val = line.chomp.split(';') case key when 1 raise "Error: #{val}" when 'ipaddr' @ip = val when 'gipaddr' @global_ip = val when 'pipaddr' @private_ip = val when 'port' @port = val @global_port = val when 'port2' @ts_port = val when 'gtvver' @version = val when '0' next else raise "WARNING: unknown response: #{key} = #{val}" end end if @ip == @private_ip @port = 80 end end |
Instance Method Details
#channel_list ⇒ Object
57 58 59 60 61 62 63 64 65 66 |
# File 'lib/garapon/api.rb', line 57 def channel_list login url = "http://#{@ip}:#{@port}/gapi/v3/channel?dev_id=#{@developer_id}>vsession=#{@session}" client = HTTPClient.new res_str = client.get_content(url) res = Oj.load(res_str, :mode => :compat) return res end |
#search(condition) ⇒ Object
68 69 70 71 72 73 74 75 76 77 78 79 80 81 |
# File 'lib/garapon/api.rb', line 68 def search(condition) login url = "http://#{@ip}:#{@port}/gapi/v3/search?dev_id=#{@developer_id}>vsession=#{@session}" client = HTTPClient.new res_str = client.post_content(url, condition) res = Oj.load(res_str, :mode => :compat) if res['status'] != 1 raise "Error: Can not get response for search: status=#{res['status']}" end return res end |