kittyverse 0.4.1 → 0.4.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Manifest.txt +3 -0
- data/lib/kittyverse.rb +10 -0
- data/lib/kittyverse/api/client.rb +72 -0
- data/lib/kittyverse/api/versions.rb +76 -0
- data/lib/kittyverse/config/colors.rb +132 -0
- data/lib/kittyverse/traits.rb +18 -9
- data/lib/kittyverse/version.rb +1 -1
- metadata +5 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2698032788d8346a7291346483e585502611d69c
|
4
|
+
data.tar.gz: f40553268c0458012235f9fbd7aa9a1eed690ec5
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: bf8ab2090846cafbb6c9673067247455c4607cad4a9fd89f852967ba70ad341661031e1b3d7b511ea2324e1e599f629074cfc216b397d0a60bc631f00f1e44ce
|
7
|
+
data.tar.gz: 53ec77865e458b19a4261b15bdd3fdabee440a171133cc3fe077ca71037aac79f76231c096be2c0a6178d484430dab2b0fbfd194e57576747808039ab709255e
|
data/Manifest.txt
CHANGED
@@ -4,7 +4,10 @@ Manifest.txt
|
|
4
4
|
README.md
|
5
5
|
Rakefile
|
6
6
|
lib/kittyverse.rb
|
7
|
+
lib/kittyverse/api/client.rb
|
8
|
+
lib/kittyverse/api/versions.rb
|
7
9
|
lib/kittyverse/cattributes.rb
|
10
|
+
lib/kittyverse/config/colors.rb
|
8
11
|
lib/kittyverse/config/fancies.rb
|
9
12
|
lib/kittyverse/config/purrstiges.rb
|
10
13
|
lib/kittyverse/config/traits.rb
|
data/lib/kittyverse.rb
CHANGED
@@ -3,6 +3,11 @@
|
|
3
3
|
## std libs
|
4
4
|
require 'date'
|
5
5
|
require 'json'
|
6
|
+
require "pp"
|
7
|
+
require "uri"
|
8
|
+
require "net/http"
|
9
|
+
require "net/https"
|
10
|
+
|
6
11
|
|
7
12
|
|
8
13
|
## 3rd party libs
|
@@ -16,6 +21,7 @@ require 'kittyverse/config/traits'
|
|
16
21
|
require 'kittyverse/config/traits_timeline'
|
17
22
|
require 'kittyverse/config/fancies'
|
18
23
|
require 'kittyverse/config/purrstiges'
|
24
|
+
require 'kittyverse/config/colors'
|
19
25
|
|
20
26
|
|
21
27
|
require 'kittyverse/mewtations'
|
@@ -28,6 +34,10 @@ require 'kittyverse/traits'
|
|
28
34
|
require 'kittyverse/cattributes'
|
29
35
|
require 'kittyverse/fancies'
|
30
36
|
|
37
|
+
## api support
|
38
|
+
require 'kittyverse/api/client'
|
39
|
+
require 'kittyverse/api/versions'
|
40
|
+
|
31
41
|
|
32
42
|
|
33
43
|
# say hello
|
@@ -0,0 +1,72 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
module Kitties
|
4
|
+
|
5
|
+
|
6
|
+
class Client
|
7
|
+
|
8
|
+
##
|
9
|
+
## todo: add (optional) close with @http.close - why? why not?
|
10
|
+
|
11
|
+
|
12
|
+
def initialize( base_uri:, token: nil )
|
13
|
+
uri = URI.parse( base_uri )
|
14
|
+
@http = Net::HTTP.new( uri.host, uri.port )
|
15
|
+
if uri.instance_of? URI::HTTPS
|
16
|
+
@http.use_ssl = true
|
17
|
+
@http.verify_mode = OpenSSL::SSL::VERIFY_NONE
|
18
|
+
end
|
19
|
+
|
20
|
+
@base_request_uri = uri.request_uri ## e.g. save /v1 etc.
|
21
|
+
## puts "base_request_uri: >#{@base_request_uri}<"
|
22
|
+
|
23
|
+
@token = token
|
24
|
+
end # method initialize
|
25
|
+
|
26
|
+
def get( service )
|
27
|
+
puts "GET #{service}"
|
28
|
+
|
29
|
+
request_uri = if @base_request_uri == "/"
|
30
|
+
service
|
31
|
+
else
|
32
|
+
"#{@base_request_uri}#{service}" ## e.g. add /v1 etc.
|
33
|
+
end
|
34
|
+
|
35
|
+
headers = if @token
|
36
|
+
{ "x-api-token" => @token }
|
37
|
+
else
|
38
|
+
{}
|
39
|
+
end
|
40
|
+
|
41
|
+
req = Net::HTTP::Get.new( request_uri, headers )
|
42
|
+
|
43
|
+
res = @http.request(req)
|
44
|
+
|
45
|
+
## todo/fix: add check for res.code == "200"
|
46
|
+
## throw exception of fail
|
47
|
+
|
48
|
+
|
49
|
+
if Kitties.debug?
|
50
|
+
# Iterate all response headers.
|
51
|
+
res.each_header do |key, value|
|
52
|
+
p "#{key} => #{value}"
|
53
|
+
end
|
54
|
+
# => "content-type => application/json; charset=utf-8"
|
55
|
+
# => "x-ratelimit-limit => 20"
|
56
|
+
# => "x-ratelimit-remaining => 19"
|
57
|
+
# => "x-ratelimit-reset => 1558079593"
|
58
|
+
# ...
|
59
|
+
end
|
60
|
+
|
61
|
+
body = res.read_body
|
62
|
+
## pp body
|
63
|
+
|
64
|
+
json = JSON.parse( body ) ## use just body (any difference?) - why? why not?
|
65
|
+
## pp json
|
66
|
+
json
|
67
|
+
end # methdo get
|
68
|
+
|
69
|
+
end ## class Client
|
70
|
+
|
71
|
+
|
72
|
+
end # module Kitties
|
@@ -0,0 +1,76 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
module Kitties
|
4
|
+
|
5
|
+
class Configuration
|
6
|
+
attr_accessor :token
|
7
|
+
attr_accessor :debug
|
8
|
+
|
9
|
+
def initialize
|
10
|
+
# try default setup via ENV variables
|
11
|
+
@token = ENV[ 'KITTIES_TOKEN' ]
|
12
|
+
@debug = false
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
## lets you use
|
17
|
+
## Kitties.configure do |config|
|
18
|
+
## config.token = 'secret'
|
19
|
+
## end
|
20
|
+
def self.configuration
|
21
|
+
@configuration ||= Configuration.new
|
22
|
+
end
|
23
|
+
|
24
|
+
def self.configure
|
25
|
+
yield( configuration )
|
26
|
+
end
|
27
|
+
|
28
|
+
### debug convenience helpers
|
29
|
+
def self.debug?() configuration.debug; end
|
30
|
+
def self.debug=(value) configuration.debug = value; end
|
31
|
+
|
32
|
+
|
33
|
+
|
34
|
+
|
35
|
+
module V0
|
36
|
+
class Client < ::Kitties::Client
|
37
|
+
def initialize
|
38
|
+
super( base_uri: "https://api.cryptokitties.co" )
|
39
|
+
end
|
40
|
+
|
41
|
+
def get_cattributes() get('/cattributes'); end
|
42
|
+
def get_kitty( id ) get("/kitties/#{id}"); end ## use get_kitty_by_id - why? why not?
|
43
|
+
end # class Client
|
44
|
+
end # module V0
|
45
|
+
|
46
|
+
|
47
|
+
|
48
|
+
|
49
|
+
module V1
|
50
|
+
###
|
51
|
+
## see https://docs.api.cryptokitties.co
|
52
|
+
|
53
|
+
class Client < ::Kitties::Client
|
54
|
+
def initialize
|
55
|
+
super( base_uri: "https://public.api.cryptokitties.co/v1",
|
56
|
+
token: Kitties.configuration.token )
|
57
|
+
end
|
58
|
+
|
59
|
+
def get_cattributes() get('/cattributes'); end
|
60
|
+
def get_kitty( id ) get("/kitties/#{id}"); end ## use get_kitty_by_id - why? why not?
|
61
|
+
def get_colors_body() get('/colors/body'); end
|
62
|
+
def get_colors_eyes() get('/colors/eyes'); end
|
63
|
+
def get_colors_secondary() get('/colors/secondary'); end
|
64
|
+
def get_colors_tertiary() get('/colors/tertiary'); end
|
65
|
+
|
66
|
+
end # class Client
|
67
|
+
end # module V1
|
68
|
+
|
69
|
+
|
70
|
+
CLIENT_V0 = V0::Client.new
|
71
|
+
CLIENT_V1 = V1::Client.new
|
72
|
+
|
73
|
+
def self.v0() CLIENT_V0; end
|
74
|
+
def self.v1() CLIENT_V1; end
|
75
|
+
|
76
|
+
end # module Kitties
|
@@ -0,0 +1,132 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
COLORS = {
|
4
|
+
## 31 colors body
|
5
|
+
meowgarine: "#fcfc95",
|
6
|
+
cornflower: "#7592fc",
|
7
|
+
icicle: "#c5e2ff",
|
8
|
+
hotcocoa: "#5e4a47",
|
9
|
+
firstblush: "#fcd0f8",
|
10
|
+
tundra: "#dbccbf",
|
11
|
+
glacier: "#ccffff",
|
12
|
+
hyacinth: "#a45de2",
|
13
|
+
shamrock: "#50c878",
|
14
|
+
shadowgrey: "#b1b1be",
|
15
|
+
salmon: "#f4a792",
|
16
|
+
orangesoda: "#f7bc56",
|
17
|
+
cottoncandy: "#ecd1eb",
|
18
|
+
mauveover: "#ded0ee",
|
19
|
+
aquamarine: "#add5d2",
|
20
|
+
nachocheez: "#fcda86",
|
21
|
+
harbourfog: "#afb4d5",
|
22
|
+
cinderella: "#5ab0f1",
|
23
|
+
greymatter: "#d1dadf",
|
24
|
+
brownies: "#b78662",
|
25
|
+
dragonfruit: "#ec79f2",
|
26
|
+
hintomint: "#d0ead2",
|
27
|
+
bananacream: "#f8f8e0",
|
28
|
+
cloudwhite: "#ffffff",
|
29
|
+
oldlace: "#ffebe9",
|
30
|
+
koala: "#85828a",
|
31
|
+
lavender: "#bc99ff",
|
32
|
+
redvelvet: "#f77272",
|
33
|
+
verdigris: "#73ffc3",
|
34
|
+
onyx: "#42414c",
|
35
|
+
martian: "#a4ff6f",
|
36
|
+
## 31 colors eyes
|
37
|
+
olive: "#729100",
|
38
|
+
pinefresh: "#177a25",
|
39
|
+
oasis: "#ccffef",
|
40
|
+
dioscuri: "#0ba09c",
|
41
|
+
isotope: "#e4ff73",
|
42
|
+
bridesmaid: "#ffc2df",
|
43
|
+
downbythebay: "#83b293",
|
44
|
+
gemini: "#ffd150",
|
45
|
+
kaleidoscope: "#bcba5e",
|
46
|
+
thundergrey: "#828282",
|
47
|
+
gold: "#fcdf35",
|
48
|
+
topaz: "#0ba09c",
|
49
|
+
mintgreen: "#43edac",
|
50
|
+
sizzurp: "#7c40ff",
|
51
|
+
chestnut: "#a56429",
|
52
|
+
strawberry: "#ef4b62",
|
53
|
+
sapphire: "#4c7aef",
|
54
|
+
forgetmenot: "#4eb4f9",
|
55
|
+
dahlia: "#b8bdff",
|
56
|
+
coralsunrise: "#ff9088",
|
57
|
+
doridnudibranch: "#fa9fff",
|
58
|
+
parakeet: "#49b749",
|
59
|
+
cyan: "#45f0f4",
|
60
|
+
pumpkin: "#ffa039",
|
61
|
+
limegreen: "#aef72f",
|
62
|
+
bubblegum: "#ef52d1",
|
63
|
+
twilightsparkle: "#ba8aff",
|
64
|
+
palejade: "#c3d8cf",
|
65
|
+
eclipse: "#484c5b",
|
66
|
+
babypuke: "#bcba5e",
|
67
|
+
autumnmoon: "#ffe8bb",
|
68
|
+
## 31 colors secondary
|
69
|
+
cyborg: "#959cae",
|
70
|
+
ooze: "#daea31",
|
71
|
+
peppermint: "#00a86b",
|
72
|
+
inflatablepool: "#4fb9c5",
|
73
|
+
prairierose: "#e0115f",
|
74
|
+
springcrocus: "#ab7fef",
|
75
|
+
egyptiankohl: "#4a4855",
|
76
|
+
poisonberry: "#773c5f",
|
77
|
+
lilac: "#e5e5f9",
|
78
|
+
apricot: "#f4a45b",
|
79
|
+
royalpurple: "#cf5be8",
|
80
|
+
padparadscha: "#ffd5c7",
|
81
|
+
swampgreen: "#44e192",
|
82
|
+
violet: "#765be8",
|
83
|
+
scarlet: "#ea5f5a",
|
84
|
+
barkbrown: "#886662",
|
85
|
+
coffee: "#756650",
|
86
|
+
lemonade: "#ffef85",
|
87
|
+
chocolate: "#c47e33",
|
88
|
+
butterscotch: "#ffce6c",
|
89
|
+
safetyvest: "#b0f852",
|
90
|
+
turtleback: "#387573",
|
91
|
+
rosequartz: "#ffaefb",
|
92
|
+
wolfgrey: "#737184",
|
93
|
+
cerulian: "#385877",
|
94
|
+
skyblue: "#83d5ff",
|
95
|
+
garnet: "#f4679a",
|
96
|
+
universe: "#494981",
|
97
|
+
royalblue: "#5b6ee8",
|
98
|
+
mertail: "#36f2bc",
|
99
|
+
pearl: "#fff8fa",
|
100
|
+
## 31 colors tertiary
|
101
|
+
hanauma: "#7accb5",
|
102
|
+
belleblue: "#afd0f7",
|
103
|
+
peach: "#f9cfad",
|
104
|
+
granitegrey: "#b1aeb9",
|
105
|
+
kittencream: "#f7ebda",
|
106
|
+
emeraldgreen: "#8be179",
|
107
|
+
bloodred: "#ff7a7a",
|
108
|
+
daffodil: "#fff09f",
|
109
|
+
sandalwood: "#b8916c",
|
110
|
+
icy: "#eef8f8",
|
111
|
+
flamingo: "#ec87ba",
|
112
|
+
seafoam: "#9eeec5",
|
113
|
+
azaleablush: "#ffccd8",
|
114
|
+
morningglory: "#887cff",
|
115
|
+
purplehaze: "#dad6e1",
|
116
|
+
missmuffett: "#f4b3f0",
|
117
|
+
summerbonnet: "#cbb0ff",
|
118
|
+
mallowflower: "#c170b1",
|
119
|
+
fallspice: "#ff9331",
|
120
|
+
dreamboat: "#fd6cd5",
|
121
|
+
periwinkle: "#cacaff",
|
122
|
+
frosting: "#ffdce6",
|
123
|
+
patrickstarfish: "#ffad97",
|
124
|
+
mintmacaron: "#b0f1f4",
|
125
|
+
shale: "#585666",
|
126
|
+
cashewmilk: "#f9efef",
|
127
|
+
buttercup: "#f4e65d",
|
128
|
+
cobalt: "#5262db",
|
129
|
+
sully: "#70f9f9",
|
130
|
+
kalahari: "#ffcf8a",
|
131
|
+
atlantis: "#2a7f96"
|
132
|
+
}
|
data/lib/kittyverse/traits.rb
CHANGED
@@ -139,15 +139,25 @@ class TraitType
|
|
139
139
|
end
|
140
140
|
end
|
141
141
|
|
142
|
-
def self.[](
|
143
|
-
##
|
144
|
-
|
145
|
-
|
142
|
+
def self.[]( key_or_index_or_offset, length=nil )
|
143
|
+
if length ## returns a slice of trait types
|
144
|
+
offset = key_or_index_or_offset
|
145
|
+
@@trait_types_by_key.values[offset, length]
|
146
146
|
else
|
147
|
-
if
|
148
|
-
|
149
|
-
|
150
|
-
|
147
|
+
if key_or_index_or_offset.is_a? Integer
|
148
|
+
index = key_or_index_or_offset
|
149
|
+
@@trait_types_by_key.values[index]
|
150
|
+
else
|
151
|
+
key = key_or_index_or_offset
|
152
|
+
if key.size == 2 && key =~ /^[A-Za-z]{2}$/ ## check for codes e.g. FU, PA, ... (or fu, pa,...)
|
153
|
+
TraitType.find_by_code( key )
|
154
|
+
else
|
155
|
+
if key.is_a? Symbol ## e.g. :body, :pattern, etc.
|
156
|
+
TraitType.find_by_key( key )
|
157
|
+
else ## assume string
|
158
|
+
TraitType.find_by_name( key )
|
159
|
+
end
|
160
|
+
end
|
151
161
|
end
|
152
162
|
end
|
153
163
|
end
|
@@ -166,7 +176,6 @@ class TraitType
|
|
166
176
|
|
167
177
|
def self.size() @@trait_types_by_key.size; end ## todo: add length alias too? why? why not?
|
168
178
|
|
169
|
-
|
170
179
|
attr_accessor :key,
|
171
180
|
:name,
|
172
181
|
:code,
|
data/lib/kittyverse/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: kittyverse
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.4.
|
4
|
+
version: 0.4.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Gerald Bauer
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2019-05-
|
11
|
+
date: 2019-05-17 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: base32-alphabets
|
@@ -69,7 +69,10 @@ files:
|
|
69
69
|
- README.md
|
70
70
|
- Rakefile
|
71
71
|
- lib/kittyverse.rb
|
72
|
+
- lib/kittyverse/api/client.rb
|
73
|
+
- lib/kittyverse/api/versions.rb
|
72
74
|
- lib/kittyverse/cattributes.rb
|
75
|
+
- lib/kittyverse/config/colors.rb
|
73
76
|
- lib/kittyverse/config/fancies.rb
|
74
77
|
- lib/kittyverse/config/purrstiges.rb
|
75
78
|
- lib/kittyverse/config/traits.rb
|