Class: Poke::API::Helpers
- Inherits:
-
Object
- Object
- Poke::API::Helpers
- Defined in:
- lib/poke-api/helpers.rb
Class Method Summary collapse
- .camel_case_lower(sym) ⇒ Object
- .d2h(input) ⇒ Object
- .generate_location_one(auth_ticket, pos) ⇒ Object
- .generate_location_two(pos) ⇒ Object
- .generate_request(auth_ticket, request) ⇒ Object
- .get_position(pos) ⇒ Object
Class Method Details
.camel_case_lower(sym) ⇒ Object
12 13 14 |
# File 'lib/poke-api/helpers.rb', line 12 def camel_case_lower(sym) sym.to_s.split('_').collect(&:capitalize).join end |
.d2h(input) ⇒ Object
35 36 37 |
# File 'lib/poke-api/helpers.rb', line 35 def d2h(input) [input].pack('d').unpack('Q').first.to_s(16).split.pack('H*') end |
.generate_location_one(auth_ticket, pos) ⇒ Object
16 17 18 19 20 21 |
# File 'lib/poke-api/helpers.rb', line 16 def generate_location_one(auth_ticket, pos) first_hash = XXhash.xxh32(auth_ticket, 0x1B845238) location_bytes = d2h(pos[0]) + d2h(pos[1]) + d2h(pos[2]) XXhash.xxh32(location_bytes, first_hash) end |
.generate_location_two(pos) ⇒ Object
23 24 25 26 27 |
# File 'lib/poke-api/helpers.rb', line 23 def generate_location_two(pos) location_bytes = d2h(pos[0]) + d2h(pos[1]) + d2h(pos[2]) XXhash.xxh32(location_bytes, seed=0x1B845238) end |
.generate_request(auth_ticket, request) ⇒ Object
29 30 31 32 33 |
# File 'lib/poke-api/helpers.rb', line 29 def generate_request(auth_ticket, request) first_hash = XXhash.xxh64(auth_ticket, 0x1B845238) XXhash.xxh64(request, first_hash) end |
.get_position(pos) ⇒ Object
8 9 10 |
# File 'lib/poke-api/helpers.rb', line 8 def get_position(pos) Geocoder.search(pos) end |