stockfighter 0.0.2 → 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 4bdefa6e0159b52f4476baedc42858dd71702d5e
4
- data.tar.gz: ef6409e0478881f99d93a0ff0b8682dec4e0127f
3
+ metadata.gz: 2a4dbaa3414c3edfb0c0d4e0982e283aa5d758a8
4
+ data.tar.gz: 3a699ce75deabe0078c0af18a3b21e5173bdec0b
5
5
  SHA512:
6
- metadata.gz: 9aa733983e97db7249013f080f079f35f2ef53fb3a1f447c6d750be0b666e7acd11a59298964971a9b1a1049d21b229ddb37600d06f6acb421b7d2f5adec11c3
7
- data.tar.gz: 025ec520598bada4e9e57f83794d18937eaf94c2abb94d189bc44f85aac2df3819436fd2dc442d99a4a3c070780d6db88492f9ec363d6b3c4706cb0fd02fde1a
6
+ metadata.gz: a85ba12c74fae4f8ad5bde80a4bb9fe89d5089441ccf18c4227f32ff1bacbac2969bf1badcc15cdea25283bb43538463eddb4ea5513466f90e6f472b7fd5abcc
7
+ data.tar.gz: 7d2e5aa2e96c0ab13b342d57b99a4653376940b93de785613e6bccba96bd1a6155e7cc21d8d45d05b9139a035f7ceb547865381448a78d61e40f62da1c665e19
data/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # Stockfighter
2
2
 
3
- A gem for interacting with the Stockfighter.io API.
3
+ A gem for interacting with the [Stockfighter.io](https://www.stockfighter.io) API.
4
4
 
5
5
  ## Installation
6
6
 
@@ -27,7 +27,7 @@ require 'stockfighter'
27
27
  # Use the GM to fetch the info automatically
28
28
 
29
29
  gm = Stockfighter::GM.new("supersecretapikey1234567")
30
- first_steps_config = gm.fetch_info_for(level: "first_steps")
30
+ first_steps_config = gm.config_for(level: "first_steps")
31
31
 
32
32
  api = Stockfighter::Api.new(first_steps_config)
33
33
 
@@ -2,24 +2,62 @@ require 'httparty'
2
2
 
3
3
  module Stockfighter
4
4
  class GM
5
- def initialize(key)
5
+ GM_URL = "https://www.stockfighter.io/gm"
6
+
7
+ attr_accessor :instance_id
8
+
9
+ def initialize(key:, level:)
6
10
  @api_key = key
7
- end
11
+ @level = level
8
12
 
9
- def config_for(level:)
10
- resp = HTTParty.post("https://www.stockfighter.io/gm/levels/#{level}", :headers => {"X-Starfighter-Authorization" => @api_key})
13
+ resp = HTTParty.post("#{GM_URL}/levels/#{level}", :headers => {"X-Starfighter-Authorization" => @api_key})
11
14
 
12
- config = {}
13
- config[:account] = resp["account"]
14
- config[:venue] = resp["venues"][0]
15
- config[:symbol] = resp["tickers"][0]
16
- config[:key] = @api_key
15
+ update_config(resp)
16
+ end
17
17
 
18
- if config[:account] && config[:venue] && config[:symbol]
19
- config
18
+ def config
19
+ if @config[:account] && @config[:venue] && @config[:symbol]
20
+ @config
20
21
  else
21
22
  nil
22
23
  end
23
24
  end
25
+
26
+ def restart
27
+ if @instance_id
28
+ resp = HTTParty.post("#{GM_URL}/instances/#{@instance_id}/restart", :headers => {"X-Starfighter-Authorization" => @api_key})
29
+ udpate_config(resp)
30
+ end
31
+ end
32
+
33
+ def stop
34
+ if @instance_id
35
+ resp = HTTParty.post("#{GM_URL}/instances/#{@instance_id}/stop", :headers => {"X-Starfighter-Authorization" => @api_key})
36
+ update_config(resp)
37
+ end
38
+ end
39
+
40
+ def resume
41
+ if @instance_id
42
+ resp = HTTParty.post("#{GM_URL}/instances/#{@instance_id}/resume", :headers => {"X-Starfighter-Authorization" => @api_key})
43
+ update_config(resp)
44
+ end
45
+ end
46
+
47
+ def active?
48
+ response = HTTParty.get("#{GM_URL}/instances/#{@instance_id}", :headers => {"X-Starfighter-Authorization" => @api_key})
49
+ response["done"] && response["ok"]
50
+ end
51
+ end
52
+
53
+ def update_config(resp)
54
+ @config = {}
55
+ @config[:key] = @api_key
56
+ @config[:account] = resp["account"]
57
+ @config[:venue] = resp["venues"][0]
58
+ @config[:symbol] = resp["tickers"][0]
59
+
60
+ @instance_id = resp["instanceId"]
24
61
  end
62
+ private :update_config
25
63
  end
@@ -1,3 +1,3 @@
1
1
  module Stockfighter
2
- VERSION = "0.0.2"
2
+ VERSION = "0.1.0"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: stockfighter
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Robert J Samson