cf-trade-client 0.1.4 → 0.1.5

Sign up to get free protection for your applications and to get access to all the features.
data/lib/client/client.rb CHANGED
@@ -15,116 +15,112 @@ limitations under the License.
15
15
  =end
16
16
  require 'faye/websocket'
17
17
  module Coinfloor
18
-
19
- class CFClient
20
- def initialize(domain,uid,pass,pkey=nil)
21
-
22
- if domain.include?("ws://")||domain.include?("wss://")
23
- @messages=[]
24
- if uid==0
25
- @con=CFAcon.new(uid,pass)
26
- else
27
- if pkey
28
- @con=CFcon.new(uid,pass,pkey)
29
- else
30
- @con=CFcon.new(uid,pass)
31
- end
32
- end
33
- @domain=domain
34
- else
35
- puts "domain must be a ws:// or wss:// formatted string, if port is not 80 it must be specified"
36
- end
37
-
38
- end
39
- def auth(ws,msg)
40
- @messages.push(:auth)
41
- nonce=msg["nonce"]
42
- result=@con.auth(nonce)
43
- ws.send(result)
44
- end
45
-
46
- def begin_connection(sendata)
47
- output=nil
48
- EM.run {
49
- ws = Faye::WebSocket::Client.new(@domain)
50
- ws.on :open do |event|
51
- end
52
-
53
- ws.on :message do |event|
54
- evtdata=event.data
55
- msg=JSON.parse(evtdata)
56
- if msg["notice"]&&msg["notice"]=="Welcome"
57
- auth(ws,msg)
58
- elsif msg["notice"].nil?
59
- ret_msg=@messages.delete_at(0)
60
- case ret_msg
61
- when nil
62
- ws.close
63
- ws=nil
64
- EM.stop
65
- when :auth
66
- if msg["error_code"]==0
67
- @messages.push(:reply)
68
- ws.send(sendata)
69
- else
70
- ws.close
71
- ws=nil
72
- EM.stop
73
- end
74
- when :reply
75
- if msg["error_code"]==0
76
- output=msg
77
- ws.close
78
- EM.stop
79
- else
80
- output=msg
81
- ws.close
82
- EM.stop
83
- end
84
- else
85
- ws.close
86
- EM.stop
87
- raise "Reply for unknown action"
88
- end
89
- elsif msg["notice"] && (@messages.count > 0)
90
- #we just ignore this until we get a message we want
91
- elsif msg["notice"] && (@messages.count == 0)
92
- ws.close
93
- EM.stop
94
- else
95
- raise "Somethings gone wrong with the client"
96
- end
97
- end# end of on message event
98
-
99
- ws.on :error do |event|
100
- EM.stop
101
- ws = nil
102
- end
103
-
104
- ws.on :close do |event|
105
- EM.stop
106
- ws = nil
107
- end
108
- }
109
- return output
110
- end
111
-
112
- def exec(cfcon_method,arguments)
113
-
114
- data=@con.send(cfcon_method.to_s,arguments)
115
-
116
- begin_connection(data)
117
- end
118
-
119
- def get_balance
120
- self.exec(:getbalance,{})
121
- # data=@con.getbalance(nil)
122
- # begin_connection(data)
123
- end
124
-
125
- def public_key
126
- @con.public_key
127
- end
128
- end
129
-
18
+ class CFClient
19
+ def initialize(domain,uid,api_key,pass,pkey=nil)
20
+
21
+ if domain.include?("ws://")||domain.include?("wss://")
22
+ @messages=[]
23
+ if uid==0
24
+ @con=CFAcon.new(uid,pass)
25
+ else
26
+ if pkey
27
+ @con=CFcon.new(uid,pass,api_key,pkey)
28
+ else
29
+ @con=CFcon.new(uid,api_key,pass)
30
+ end
31
+ end
32
+ @domain=domain
33
+ else
34
+ puts "domain must be a ws:// or wss:// formatted string, if port is not 80 it must be specified"
35
+ end
36
+
37
+ end
38
+ def auth(ws,msg)
39
+ @messages.push(:auth)
40
+ nonce=msg["nonce"]
41
+ result=@con.auth(nonce)
42
+ ws.send(result)
43
+ end
44
+
45
+ def begin_connection(sendata)
46
+ output=nil
47
+ EM.run {
48
+ ws = Faye::WebSocket::Client.new(@domain)
49
+ ws.on :open do |event|
50
+ end
51
+
52
+ ws.on :message do |event|
53
+ evtdata=event.data
54
+ msg=JSON.parse(evtdata)
55
+ if msg["notice"]&&msg["notice"]=="Welcome"
56
+ auth(ws,msg)
57
+ elsif msg["notice"].nil?
58
+ ret_msg=@messages.delete_at(0)
59
+ case ret_msg
60
+ when nil
61
+ ws.close
62
+ ws=nil
63
+ EM.stop
64
+ when :auth
65
+ if msg["error_code"]==0
66
+ @messages.push(:reply)
67
+ ws.send(sendata)
68
+ else
69
+ ws.close
70
+ ws=nil
71
+ EM.stop
72
+ end
73
+ when :reply
74
+ if msg["error_code"]==0
75
+ output=msg
76
+ ws.close
77
+ EM.stop
78
+ else
79
+ output=msg
80
+ ws.close
81
+ EM.stop
82
+ end
83
+ else
84
+ ws.close
85
+ EM.stop
86
+ raise "Reply for unknown action"
87
+ end
88
+ elsif msg["notice"] && (@messages.count > 0)
89
+ #we just ignore this until we get a message we want
90
+ elsif msg["notice"] && (@messages.count == 0)
91
+ ws.close
92
+ EM.stop
93
+ else
94
+ raise "Somethings gone wrong with the client"
95
+ end
96
+ end# end of on message event
97
+
98
+ ws.on :error do |event|
99
+ EM.stop
100
+ ws = nil
101
+ end
102
+
103
+ ws.on :close do |event|
104
+ EM.stop
105
+ ws = nil
106
+ end
107
+ }
108
+ return output
109
+ end
110
+
111
+ def exec(cfcon_method,arguments)
112
+
113
+ data=@con.send(cfcon_method.to_s,arguments)
114
+
115
+ begin_connection(data)
116
+ end
117
+
118
+ def get_balance
119
+ self.exec(:getbalance,{})
120
+ end
121
+
122
+ def public_key
123
+ @con.public_key
124
+ end
125
+ end
130
126
  end
@@ -22,7 +22,7 @@ module Coinfloor
22
22
  # All method calls return json which is to be sent to the API.
23
23
  class CFcon
24
24
  # coinfloor user trade id, password
25
- def initialize(uid,password,pkey=nil)
25
+ def initialize(uid,password,api_key,pkey=nil)
26
26
  @uid=uid
27
27
  @uid_byte=LibEcp.gen_uid(uid)
28
28
  if pkey
@@ -33,7 +33,7 @@ module Coinfloor
33
33
 
34
34
  end
35
35
  @public_key=LibEcp.gen_pub(@private_key)
36
- @cookie=LibEcp.gen_cookie(@uid_byte)
36
+ @cookie=api_key
37
37
  @password=nil
38
38
  end
39
39
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cf-trade-client
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.4
4
+ version: 0.1.5
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2014-01-15 00:00:00.000000000 Z
12
+ date: 2014-01-19 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: faye-websocket
@@ -34,7 +34,7 @@ dependencies:
34
34
  requirements:
35
35
  - - ~>
36
36
  - !ruby/object:Gem::Version
37
- version: 0.1.0
37
+ version: 0.1.2
38
38
  type: :runtime
39
39
  prerelease: false
40
40
  version_requirements: !ruby/object:Gem::Requirement
@@ -42,7 +42,7 @@ dependencies:
42
42
  requirements:
43
43
  - - ~>
44
44
  - !ruby/object:Gem::Version
45
- version: 0.1.0
45
+ version: 0.1.2
46
46
  - !ruby/object:Gem::Dependency
47
47
  name: json
48
48
  requirement: !ruby/object:Gem::Requirement
@@ -70,7 +70,7 @@ files:
70
70
  - lib/trade_client.rb
71
71
  - lib/client/client.rb
72
72
  - lib/trade_api/trade_api.rb
73
- homepage: https://github.com/coinfloor/trade-client
73
+ homepage: http://coinfloor.co.uk
74
74
  licenses:
75
75
  - APACHE 2.0
76
76
  post_install_message:
@@ -94,6 +94,7 @@ rubyforge_project:
94
94
  rubygems_version: 1.8.25
95
95
  signing_key:
96
96
  specification_version: 3
97
- summary: A ruby client library to trade on the Coinfloor platform using their API
97
+ summary: An example ruby client library to trade on the Coinfloor platform using their
98
+ API
98
99
  test_files: []
99
100
  has_rdoc: