Class: PlusAPI

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(token) ⇒ PlusAPI

Returns a new instance of PlusAPI.



9
10
11
12
# File 'lib/plusapi.rb', line 9

def initialize(token)
  @token = token
  @bilgi = "PlusAPI | Piyasa Verileri Sınıfı"
end

Instance Attribute Details

#bilgiObject

Returns the value of attribute bilgi.



7
8
9
# File 'lib/plusapi.rb', line 7

def bilgi
  @bilgi
end

#tokenObject

Returns the value of attribute token.



7
8
9
# File 'lib/plusapi.rb', line 7

def token
  @token
end

Instance Method Details

#hisse_sepetObject



39
40
41
42
# File 'lib/plusapi.rb', line 39

def hisse_sepet()
  istek = istek_at("/hisse/sepet")
  return istek
end

#hisse_ver(sembol = "") ⇒ Object



34
35
36
37
# File 'lib/plusapi.rb', line 34

def hisse_ver(sembol = "")
  istek = istek_at("/hisse", sembol)
  return istek
end

#istek_at(endpoint, sembol = "") ⇒ Object



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/plusapi.rb', line 14

def istek_at(endpoint, sembol = "")
  begin
    api = "http://plusapi.org/api" + endpoint + "?token=" + @token + ("&sembol=#{sembol}" if sembol != "").to_s
    uri = URI(api)
    res = Net::HTTP.get_response(uri)
    if res.is_a?(Net::HTTPSuccess)
      return JSON.parse(res.body)
    else
      return {
        error => "Bir hata oluştu sayfa boş döndü"
      }
    end
  rescue Errno::ECONNREFUSED
    return {
      error => "Sembol bulunamadı ya da bir hata oluştu",
      code => 500
    }
  end
end

#kripto_haberObject



49
50
51
52
# File 'lib/plusapi.rb', line 49

def kripto_haber()
  istek = istek_at("/kripto/haber")
  return istek
end

#kripto_sepetObject



54
55
56
57
# File 'lib/plusapi.rb', line 54

def kripto_sepet()
  istek = istek_at("/kripto/sepet")
  return istek
end

#kripto_ver(sembol = "") ⇒ Object



44
45
46
47
# File 'lib/plusapi.rb', line 44

def kripto_ver(sembol = "")
  istek = istek_at("/kripto", sembol)
  return istek
end