Class: Poke::API::Client
- Inherits:
-
Object
- Object
- Poke::API::Client
- Includes:
- Logging
- Defined in:
- lib/poke-api/client.rb
Instance Attribute Summary collapse
-
#alt ⇒ Object
Returns the value of attribute alt.
-
#endpoint ⇒ Object
Returns the value of attribute endpoint.
-
#lat ⇒ Object
Returns the value of attribute lat.
-
#lng ⇒ Object
Returns the value of attribute lng.
-
#sig_path ⇒ Object
Returns the value of attribute sig_path.
-
#ticket ⇒ Object
Returns the value of attribute ticket.
Instance Method Summary collapse
- #activate_signature(file_path) ⇒ Object
- #call ⇒ Object
-
#initialize ⇒ Client
constructor
A new instance of Client.
- #inspect ⇒ Object
- #login(username, password, provider) ⇒ Object
- #store_lat_lng(lat, lng) ⇒ Object
- #store_location(loc) ⇒ Object
Methods included from Logging
formatter=, log_level=, #logger
Constructor Details
#initialize ⇒ Client
Returns a new instance of Client.
7 8 9 10 11 12 13 14 15 16 |
# File 'lib/poke-api/client.rb', line 7 def initialize @auth = nil @endpoint = 'https://pgorelease.nianticlabs.com/plfe/rpc' @reqs = [] @lat = 0 @lng = 0 @alt = 8 @ticket = Auth::Ticket.new @sig_path = nil end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method, *args) ⇒ Object (private)
82 83 84 85 86 87 |
# File 'lib/poke-api/client.rb', line 82 def method_missing(method, *args) POGOProtos::Networking::Requests::RequestType.const_get(method.upcase) @reqs << (args.empty? ? method.to_sym.upcase : { method.to_sym.upcase => args.first }) rescue NameError super end |
Instance Attribute Details
#alt ⇒ Object
Returns the value of attribute alt.
5 6 7 |
# File 'lib/poke-api/client.rb', line 5 def alt @alt end |
#endpoint ⇒ Object
Returns the value of attribute endpoint.
5 6 7 |
# File 'lib/poke-api/client.rb', line 5 def endpoint @endpoint end |
#lat ⇒ Object
Returns the value of attribute lat.
5 6 7 |
# File 'lib/poke-api/client.rb', line 5 def lat @lat end |
#lng ⇒ Object
Returns the value of attribute lng.
5 6 7 |
# File 'lib/poke-api/client.rb', line 5 def lng @lng end |
#sig_path ⇒ Object
Returns the value of attribute sig_path.
5 6 7 |
# File 'lib/poke-api/client.rb', line 5 def sig_path @sig_path end |
#ticket ⇒ Object
Returns the value of attribute ticket.
5 6 7 |
# File 'lib/poke-api/client.rb', line 5 def ticket @ticket end |
Instance Method Details
#activate_signature(file_path) ⇒ Object
52 53 54 55 56 57 58 59 |
# File 'lib/poke-api/client.rb', line 52 def activate_signature(file_path) if File.exist?(path) logger.info "[+] File #{file_path} has been set for signature generation" @sig_path = path else raise Errors::InvalidSignatureFilePath, file_path end end |
#call ⇒ Object
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/poke-api/client.rb', line 35 def call raise Errors::LoginRequired unless @auth raise Errors::NoRequests if @reqs.empty? req = RequestBuilder.new(@auth, [@lat, @lng, @alt], @endpoint) begin resp = req.request(@reqs, self) rescue StandardError => ex raise Errors::UnknownProtoFault, ex ensure @reqs = [] logger.info '[+] Cleaning up RPC requests' end resp end |
#inspect ⇒ Object
75 76 77 78 |
# File 'lib/poke-api/client.rb', line 75 def inspect "#<#{self.class.name} @auth=#{@auth} @reqs=#{@reqs} " \ "@lat=#{@lat} @lng=#{@lng} @alt=#{@alt}>" end |
#login(username, password, provider) ⇒ Object
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/poke-api/client.rb', line 18 def login(username, password, provider) provider = provider.upcase raise Errors::InvalidProvider, provider unless %w(PTC GOOGLE).include?(provider) logger.info "[+] Logging in user: #{username}" begin @auth = Auth.const_get(provider).new(username, password) @auth.connect rescue StandardError => ex raise Errors::LoginFailure.new(provider, ex) end get_hatched_eggs call logger.info "[+] Login with #{provider} Successful" end |
#store_lat_lng(lat, lng) ⇒ Object
70 71 72 73 |
# File 'lib/poke-api/client.rb', line 70 def store_lat_lng(lat, lng) logger.info "[+] Lat/Long: #{lat}, #{lng}" @lat, @lng = lat, lng end |
#store_location(loc) ⇒ Object
61 62 63 64 65 66 67 68 |
# File 'lib/poke-api/client.rb', line 61 def store_location(loc) pos = Poke::API::Helpers.get_position(loc).first logger.info "[+] Given location: #{pos.address}" logger.info "[+] Lat/Long: #{pos.latitude}, #{pos.longitude}" @lat = pos.latitude @lng = pos.longitude end |