akaynak 0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/lib/akaynak.rb +15 -0
- data/lib/akaynak/configuration.rb +23 -0
- data/lib/akaynak/data.rb +65 -0
- data/lib/akaynak/date.rb +15 -0
- data/lib/akaynak/xml_body.rb +36 -0
- data/lib/core-ext/hash.rb +16 -0
- metadata +50 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: d7fe3caa63a3856d56e7d3b087f255ce76eec7cb
|
4
|
+
data.tar.gz: a7dff720bc31349977b6016e0755b12a581fcb69
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: dfed44018e581fce8ccec15d0ffbb3eecdd975f2a60b559bfdab9b4aa82cf573205fba9d23f28730485b9db52ed60343c7012e3b0279344d3010533008312cfb
|
7
|
+
data.tar.gz: 57384214846b5aa6c837e11be149fa2e33807f6f3933bdc195112dc3461d07dc88d11964a29cbab9cdf30424932b02e9bd8e111a3d9ba81db36bda5664222935
|
data/lib/akaynak.rb
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
require 'net/http'
|
2
|
+
require 'net/https'
|
3
|
+
require 'core-ext/hash'
|
4
|
+
|
5
|
+
require 'akaynak/configuration'
|
6
|
+
require 'akaynak/data'
|
7
|
+
require 'akaynak/date'
|
8
|
+
require 'akaynak/xml_body'
|
9
|
+
|
10
|
+
module AKaynak
|
11
|
+
def self.root
|
12
|
+
File.expand_path('../..', __FILE__)
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
@@ -0,0 +1,23 @@
|
|
1
|
+
module AKaynak
|
2
|
+
# Used to set up and modify settings for the notifier.
|
3
|
+
class Configuration
|
4
|
+
attr_accessor :host
|
5
|
+
attr_accessor :port
|
6
|
+
attr_accessor :usercode
|
7
|
+
attr_accessor :password
|
8
|
+
|
9
|
+
def initialize
|
10
|
+
@host = 'data.altinkaynak.com'
|
11
|
+
@port = 80
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
class << self
|
16
|
+
attr_accessor :configuration
|
17
|
+
end
|
18
|
+
|
19
|
+
def self.configure
|
20
|
+
self.configuration ||= Configuration.new
|
21
|
+
yield configuration
|
22
|
+
end
|
23
|
+
end
|
data/lib/akaynak/data.rb
ADDED
@@ -0,0 +1,65 @@
|
|
1
|
+
module AKaynak
|
2
|
+
class Data
|
3
|
+
def self.get_currency(opts={})
|
4
|
+
final_result = {status: false, error_code: nil, error_message: nil}
|
5
|
+
#valid_options = opts.only(:from, :start_date, :stop_date, :turkish)
|
6
|
+
#valid_options.merge!(:start_date => NetGSM::DATE.now) unless valid_options[:start_date]
|
7
|
+
#valid_options.merge!(:stop_date => NetGSM::DATE.n_hour_from_now(1)) unless valid_options[:stop_date]
|
8
|
+
|
9
|
+
body = AKaynak::XmlBody.get_currency()
|
10
|
+
|
11
|
+
response = send_request(body)
|
12
|
+
|
13
|
+
result = parse_response(response)
|
14
|
+
if result
|
15
|
+
final_result[:status] = true
|
16
|
+
final_result[:result] = result
|
17
|
+
end
|
18
|
+
return final_result
|
19
|
+
end
|
20
|
+
|
21
|
+
def sms_status
|
22
|
+
'OK status'
|
23
|
+
end
|
24
|
+
|
25
|
+
def check_balance
|
26
|
+
'OK Balance'
|
27
|
+
end
|
28
|
+
|
29
|
+
def initialize(auth_options={})
|
30
|
+
@auth_options = auth_options
|
31
|
+
end
|
32
|
+
|
33
|
+
def self.send_request(body)
|
34
|
+
header = {
|
35
|
+
"Content-Type" => "text/xml; charset=utf-8",
|
36
|
+
"Content-Length" => body.bytesize.to_s,
|
37
|
+
"Accept" => "*/*"
|
38
|
+
}
|
39
|
+
|
40
|
+
request = Net::HTTP::Post.new('/DataService.asmx', header)
|
41
|
+
request.body = body
|
42
|
+
#puts "Request #{@header} #{request.body} "
|
43
|
+
response = Net::HTTP.new(AKaynak.configuration.host, AKaynak.configuration.port).start {|http| http.request(request) }
|
44
|
+
#puts "Response #{response.code} #{response.message}: #{response.body}"
|
45
|
+
|
46
|
+
# parser = XMLRPC::XMLParser::REXMLStreamParser::StreamListener.new
|
47
|
+
# parser.parse(response.body)
|
48
|
+
|
49
|
+
return response.body
|
50
|
+
end
|
51
|
+
|
52
|
+
def self.parse_response(body)
|
53
|
+
require 'active_support/core_ext/hash/conversions'
|
54
|
+
begin
|
55
|
+
result_hash = Hash.from_xml(body)
|
56
|
+
result_xml = result_hash["Envelope"]['Body']["GetCurrencyResponse"]["GetCurrencyResult"]
|
57
|
+
currency_hash = Hash.from_xml(result_xml)
|
58
|
+
return currency_hash
|
59
|
+
rescue Exception => e
|
60
|
+
puts "ERROR: #{e.message}"
|
61
|
+
return nil
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
data/lib/akaynak/date.rb
ADDED
@@ -0,0 +1,36 @@
|
|
1
|
+
module AKaynak
|
2
|
+
class XmlBody
|
3
|
+
def self.get_currency()
|
4
|
+
result = "<soapenv:Envelope xmlns:soapenv='http://schemas.xmlsoap.org/soap/envelope/' xmlns:data='http://data.altinkaynak.com/'>
|
5
|
+
<soapenv:Header>
|
6
|
+
<data:AuthHeader>
|
7
|
+
<data:Username>#{AKaynak.configuration.usercode}</data:Username>
|
8
|
+
<data:Password>#{AKaynak.configuration.password}</data:Password>
|
9
|
+
</data:AuthHeader>
|
10
|
+
</soapenv:Header>
|
11
|
+
<soapenv:Body>
|
12
|
+
<data:GetCurrency/>
|
13
|
+
</soapenv:Body>
|
14
|
+
</soapenv:Envelope>"
|
15
|
+
|
16
|
+
return result
|
17
|
+
end
|
18
|
+
|
19
|
+
def self.get_gold()
|
20
|
+
result = "<soapenv:Envelope xmlns:soapenv='http://schemas.xmlsoap.org/soap/envelope/' xmlns:data='http://data.altinkaynak.com/'>
|
21
|
+
<soapenv:Header>
|
22
|
+
<data:AuthHeader>
|
23
|
+
<data:Username>#{AKaynak.configuration.usercode}</data:Username>
|
24
|
+
<data:Password>#{AKaynak.configuration.password}</data:Password>
|
25
|
+
</data:AuthHeader>
|
26
|
+
</soapenv:Header>
|
27
|
+
<soapenv:Body>
|
28
|
+
<data:GetGold/>
|
29
|
+
</soapenv:Body>
|
30
|
+
</soapenv:Envelope>"
|
31
|
+
|
32
|
+
#puts result
|
33
|
+
return result
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
class Hash
|
2
|
+
# https://raw.github.com/lukeredpath/clickatell/master/lib/core-ext/hash.rb
|
3
|
+
# Returns a new hash containing only the keys specified
|
4
|
+
# that exist in the current hash.
|
5
|
+
#
|
6
|
+
# {:a => '1', :b => '2', :c => '3'}.only(:a, :c)
|
7
|
+
# # => {:a => '1', :c => '3'}
|
8
|
+
#
|
9
|
+
# Keys that do not exist in the original hash are ignored.
|
10
|
+
def only(*keys)
|
11
|
+
inject( {} ) do |new_hash, (key, value)|
|
12
|
+
new_hash[key] = value if keys.include?(key)
|
13
|
+
new_hash
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
metadata
ADDED
@@ -0,0 +1,50 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: akaynak
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: '0.0'
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- IPOS - Huseyin Gomleksizoglu
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2016-02-24 00:00:00.000000000 Z
|
12
|
+
dependencies: []
|
13
|
+
description: This gem is for getting currency data from data.altinkaynak.com
|
14
|
+
email: huseyin.gomleksizoglu@ipos.com.tr
|
15
|
+
executables: []
|
16
|
+
extensions: []
|
17
|
+
extra_rdoc_files: []
|
18
|
+
files:
|
19
|
+
- lib/akaynak.rb
|
20
|
+
- lib/core-ext/hash.rb
|
21
|
+
- lib/akaynak/configuration.rb
|
22
|
+
- lib/akaynak/data.rb
|
23
|
+
- lib/akaynak/date.rb
|
24
|
+
- lib/akaynak/xml_body.rb
|
25
|
+
homepage: http://rubygems.org/gems/akaynak
|
26
|
+
licenses:
|
27
|
+
- MIT
|
28
|
+
metadata: {}
|
29
|
+
post_install_message:
|
30
|
+
rdoc_options: []
|
31
|
+
require_paths:
|
32
|
+
- lib
|
33
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
34
|
+
requirements:
|
35
|
+
- - '>='
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: '0'
|
38
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
39
|
+
requirements:
|
40
|
+
- - '>='
|
41
|
+
- !ruby/object:Gem::Version
|
42
|
+
version: '0'
|
43
|
+
requirements: []
|
44
|
+
rubyforge_project:
|
45
|
+
rubygems_version: 2.1.11
|
46
|
+
signing_key:
|
47
|
+
specification_version: 4
|
48
|
+
summary: Get Currency data from data.altinkaynak.com
|
49
|
+
test_files: []
|
50
|
+
has_rdoc:
|