~vesto/huginn_venmo_agent

35bb33320f78698c4eba8f824202579f923cde53 — Steve Gattuso 3 years ago baf533f
cleanup from rename
M lib/huginn_venmo_agents.rb => lib/huginn_venmo_agents.rb +3 -3
@@ 1,5 1,5 @@
require 'huginn_agent'
require 'huginn_venmo_agent/railtie' if defined?(Rails)
require 'huginn_venmo_agents/railtie' if defined?(Rails)

HuginnAgent.register 'huginn_venmo_agent/read_venmo_timeline_agent'
HuginnAgent.register 'huginn_venmo_agent/create_venmo_transaction_agent'
HuginnAgent.register 'huginn_venmo_agents/read_venmo_timeline_agent'
HuginnAgent.register 'huginn_venmo_agents/create_venmo_transaction_agent'

M lib/huginn_venmo_agents/create_venmo_transaction_agent.rb => lib/huginn_venmo_agents/create_venmo_transaction_agent.rb +8 -14
@@ 56,9 56,16 @@ module Agents
    end

    def check
      if memory['last_success'].nil?
        true
      else
        memory['last_success']
      end
    end

    def receive(incoming_events)
      memory['last_success'] = false

      incoming_events.each do |event|
        if event['amount'] < 0
          error('Disallowing payment (this Agent is too new/dangerous for this to be enabled)')


@@ 84,25 91,12 @@ module Agents

        if resp.status >= 200 && resp.status < 300
          log("Success!")
          memory['last_success'] = true
          create_event payload: resp.body.parse
        else
          error("Error creating payment (#{resp.status}): #{resp.body.parse}")
        end
      end
    end

    def self.generate_device_id
      random_string = '88884260-05O3-8U81-58I1-2WA76F357GR9'.split('').map do |char|
        if /^[0-9]$/.match?(char)
          (0..9).to_a.sample
        elsif char == '-'
          '-'
        else
          ('A'..'Z').to_a.sample
        end
      end

      random_string.join('')
    end
  end
end

M lib/huginn_venmo_agents/railtie.rb => lib/huginn_venmo_agents/railtie.rb +1 -1
@@ 1,4 1,4 @@
require 'huginn_venmo_agent'
require 'huginn_venmo_agents'
require 'rails'

module MyGem

M lib/huginn_venmo_agents/tasks/venmo.rake => lib/huginn_venmo_agents/tasks/venmo.rake +15 -1
@@ 1,5 1,19 @@
require 'huginn_venmo_agent'

def generate_device_id
  random_string = '88884260-05O3-8U81-58I1-2WA76F357GR9'.split('').map do |char|
    if /^[0-9]$/.match?(char)
      (0..9).to_a.sample
    elsif char == '-'
      '-'
    else
      ('A'..'Z').to_a.sample
    end
  end

  random_string.join('')
end

namespace :venmo do
  API_BASE = 'https://api.venmo.com/v1'



@@ 27,7 41,7 @@ namespace :venmo do
  end

  task authenticate: :environment do
    device_id = Agents::VenmoAgent.generate_device_id
    device_id = generate_device_id
    puts "Your device ID is #{device_id} (save this!)"
    print "Venmo Username: "
    username = STDIN.gets.chomp