source stringclasses 1
value | repo stringlengths 5 63 | repo_url stringlengths 24 82 | path stringlengths 5 167 | language stringclasses 1
value | license stringclasses 5
values | stars int64 10 51.4k | ref stringclasses 23
values | size_bytes int64 200 258k | text stringlengths 137 258k |
|---|---|---|---|---|---|---|---|---|---|
github | itteco/service_merchant | https://github.com/itteco/service_merchant | demo.rb | Ruby | mit | 191 | master | 2,340 | #!/usr/bin/ruby
#
# Demo of subscription management
require File.dirname(__FILE__) + '/subscription_management/subscription_management'
require 'rubygems'
require 'active_merchant'
options = {
:account_id => 'Test',
:account_country => 'US',
:account_state => 'CA',
:tariff_plan... |
github | itteco/service_merchant | https://github.com/itteco/service_merchant | tasks/service_merchant.rake | Ruby | mit | 191 | master | 385 | require File.dirname(__FILE__)+'/../tracker/tasks/schema'
require File.dirname(__FILE__)+'/../subscription_management/tasks/schema'
namespace :service_merchant do
desc "Create all tables"
task :create_all_tables => ["tracker:create_tables", "subscription:create_tables"]
desc "Drop all tables"
task :drop_all_t... |
github | itteco/service_merchant | https://github.com/itteco/service_merchant | sample_app/config/boot.rb | Ruby | mit | 191 | master | 2,770 | # Don't change this file!
# Configure your app in config/environment.rb and config/environments/*.rb
RAILS_ROOT = "#{File.dirname(__FILE__)}/.." unless defined?(RAILS_ROOT)
module Rails
class << self
def boot!
unless booted?
preinitialize
pick_boot.run
end
end
def booted?
... |
github | itteco/service_merchant | https://github.com/itteco/service_merchant | sample_app/config/environment.rb | Ruby | mit | 191 | master | 4,254 | # Be sure to restart your server when you modify this file
# Uncomment below to force Rails into production mode when
# you don't control web/app server and can't set it the proper way
# ENV['RAILS_ENV'] ||= 'production'
# Specifies gem version of Rails to use when vendor/rails is not present
RAILS_GEM_VERSION = '2.1... |
github | itteco/service_merchant | https://github.com/itteco/service_merchant | sample_app/config/routes.rb | Ruby | mit | 191 | master | 1,959 | ActionController::Routing::Routes.draw do |map|
# The priority is based upon order of creation: first created -> highest priority.
# Sample of regular route:
# map.connect 'products/:id', :controller => 'catalog', :action => 'view'
# Keep in mind you can assign values other than :controller and :action
# ... |
github | itteco/service_merchant | https://github.com/itteco/service_merchant | sample_app/config/environments/production.rb | Ruby | mit | 191 | master | 908 | # Settings specified here will take precedence over those in config/environment.rb
# The production environment is meant for finished, "live" apps.
# Code is not reloaded between requests
config.cache_classes = true
# Use a different logger for distributed setups
# config.logger = SyslogLogger.new
# Full error repor... |
github | itteco/service_merchant | https://github.com/itteco/service_merchant | sample_app/app/controllers/admin_controller.rb | Ruby | mit | 191 | master | 994 | class AdminController < ApplicationController
layout 'admin'
def initialize
super
@sm = SubscriptionManager
end
def index
end
def tariff_plan
@tariff_plan = @sm.all_tariff_plans[params[:id]]
@active_subscriptions = Subscription.find(:all, :conditions => ['tariff_plan_id = ? and status = ... |
github | itteco/service_merchant | https://github.com/itteco/service_merchant | sample_app/app/controllers/application.rb | Ruby | mit | 191 | master | 1,303 | # Filters added to this controller apply to all controllers in the application.
# Likewise, all the methods added will be available for all controllers.
class ApplicationController < ActionController::Base
helper :all # include all helpers, all the time
layout 'default'
# See ActionController::RequestForgeryPr... |
github | itteco/service_merchant | https://github.com/itteco/service_merchant | sample_app/app/controllers/subscription_controller.rb | Ruby | mit | 191 | master | 4,288 | class SubscriptionController < ApplicationController
def initialize
super
# sample data, would be replaced with authentication system
@current_account = {:first_name => 'John', :last_name => 'Smith', :id => 'Test', :country => 'US', :state => 'CA'}
@sm = SubscriptionManager
end
def index
@ac... |
github | itteco/service_merchant | https://github.com/itteco/service_merchant | sample_app/lib/tasks/sample_app.rake | Ruby | mit | 191 | master | 509 | namespace :sample_app do
# Prevent visibility outside sample_app dir
#if %r(^#{Dir.getwd}) =~ __FILE__ and %r(/sample_app/$) =~ Dir.getwd
if Dir.getwd =~ /sample_app/
desc "Create subscription management and require plugins' database tables"
task :setup => %w(dependencies tracker:create_tables subscriptio... |
github | itteco/service_merchant | https://github.com/itteco/service_merchant | recurring_billing/test/test_helper.rb | Ruby | mit | 191 | master | 3,767 | #!/usr/bin/env ruby
require 'rubygems'
require 'test/unit'
require 'active_merchant'
require File.dirname(__FILE__) + '/../lib/gateways'
# Turn off invalid certificate crashes
require 'openssl'
silence_warnings do
OpenSSL::SSL::VERIFY_PEER = OpenSSL::SSL::VERIFY_NONE
end
ActiveMerchant::Billing::Base.mode = :test... |
github | itteco/service_merchant | https://github.com/itteco/service_merchant | recurring_billing/test/remote/recurring_billing_test.rb | Ruby | mit | 191 | master | 1,215 | require File.dirname(__FILE__) + '/../test_helper'
class RecurringBillingRemoteTest < Test::Unit::TestCase
def setup
@card = credit_card()
end
def perform_generic_test(gateway)
random_invoice = "%06d" % rand(999999)
payment_options = {
:subscription_name => 'Test Subscription 1337',
... |
github | itteco/service_merchant | https://github.com/itteco/service_merchant | recurring_billing/test/remote/paypal_test.rb | Ruby | mit | 191 | master | 1,437 | require File.dirname(__FILE__) + '/../test_helper'
class PaypalGatewayRemoteTest < Test::Unit::TestCase
def setup
cred = fixtures(:paypal)
assert @gw = RecurringBilling::PaypalGateway.new(cred.update({:is_test=>true}))
assert_equal @gw.name, 'PayPal Website Payments Pro (US)'
@card = credit_card()
... |
github | itteco/service_merchant | https://github.com/itteco/service_merchant | recurring_billing/test/remote/authorize_net_test.rb | Ruby | mit | 191 | master | 1,144 | require File.dirname(__FILE__) + '/../test_helper'
class AuthorizeNetGatewayRemoteTest < Test::Unit::TestCase
def setup
credentials = fixtures(:authorize_net)
assert @gw = RecurringBilling::AuthorizeNetGateway.new(credentials.update({:is_test => true}))
assert_equal @gw.name, 'Authorize.net'
@card... |
github | itteco/service_merchant | https://github.com/itteco/service_merchant | recurring_billing/test/unit/utils_test.rb | Ruby | mit | 191 | master | 685 | require File.dirname(__FILE__) + '/../test_helper'
class UtilsTest < Test::Unit::TestCase
def test_months_between
def d(string);return Date.parse(string);end
assert months_between(d("2008/10/01"), d("2008/10/01")), 0
assert months_between(d("2008/10/02"), d("2008/10/01")), 0
assert months_betwee... |
github | itteco/service_merchant | https://github.com/itteco/service_merchant | recurring_billing/test/unit/authorize_net_gateway_class_test.rb | Ruby | mit | 191 | master | 2,374 | require File.dirname(__FILE__) + '/../test_helper'
class AuthorizeNetGatewayTest < Test::Unit::TestCase
def setup
credentials = fixtures(:authorize_net)
assert @gw = RecurringBilling::AuthorizeNetGateway.new(credentials.update({:is_test => true}))
assert_equal @gw.name, 'Authorize.net'
@card = cre... |
github | itteco/service_merchant | https://github.com/itteco/service_merchant | recurring_billing/test/unit/paypal_gateway_class_test.rb | Ruby | mit | 191 | master | 796 | require File.dirname(__FILE__) + '/../test_helper'
class PaypalGatewayTest < Test::Unit::TestCase
def setup
cred = fixtures(:paypal)
assert @gw = RecurringBilling::PaypalGateway.new(cred.update({:is_test=>true}))
assert_equal @gw.name, 'PayPal Website Payments Pro (US)'
@card = credit_card()
end
... |
github | itteco/service_merchant | https://github.com/itteco/service_merchant | recurring_billing/test/unit/recurring_billing_gateway_class_test.rb | Ruby | mit | 191 | master | 1,209 | require File.dirname(__FILE__) + '/../test_helper'
class RecurringBillingGatewayTest < Test::Unit::TestCase
def perform_generic_test(gateway)
credentials = fixtures(gateway)
assert gw = RecurringBilling::RecurringBillingGateway.get_instance(credentials)
end
# Checking separate_create_update_params_from... |
github | itteco/service_merchant | https://github.com/itteco/service_merchant | recurring_billing/lib/dependencies.rb | Ruby | mit | 191 | master | 376 | require 'rubygems'
gem 'activemerchant'
require 'active_merchant'
#TODO: Autodiscover new libs from vendor and add them to load path
$: << File.dirname(__FILE__) + "/../../vendor/money-1.7.1/lib"
require "money"
gem 'activesupport'
require 'active_support/core_ext/string/inflections'
class String # :nodoc:
include... |
github | itteco/service_merchant | https://github.com/itteco/service_merchant | recurring_billing/lib/utils.rb | Ruby | mit | 191 | master | 3,013 | # This module contains common functions that ServiceMerchant uses.
module Utils
#Counts nubmer of months between two dates
#
# 2008/1/1, 2007/12/31 => 1
# 2008/9/10, 2009/10/20 => 13
# ETC
def months_between(date1, date2)
if date1 > date2
recent_date = date1.to_date
past_date = date2.to_dat... |
github | itteco/service_merchant | https://github.com/itteco/service_merchant | recurring_billing/lib/recurring_billing.rb | Ruby | mit | 191 | master | 5,178 | require File.dirname(__FILE__) + '/dependencies'
# RecurringBilling module provides common API for managing recurring billing operations
# via remote gateway. All manipulations are done through instances of RecurringBillingGateway
# and its descendants (though direct use of that class descendants is discouraged).
#
# ... |
github | itteco/service_merchant | https://github.com/itteco/service_merchant | recurring_billing/lib/gateways.rb | Ruby | mit | 191 | master | 214 | require File.dirname(__FILE__) + '/utils'
require File.dirname(__FILE__) + '/recurring_billing'
require File.dirname(__FILE__) + '/am_extensions'
Dir[File.dirname(__FILE__) + '/gateways/*.rb'].each{|g| require g} |
github | itteco/service_merchant | https://github.com/itteco/service_merchant | recurring_billing/lib/am_extensions/paypal_extension.rb | Ruby | mit | 191 | master | 8,778 | module ActiveMerchant #:nodoc:
module Billing #:nodoc:
class PaypalGateway < Gateway#:nodoc:
# this file was originally located in activemerchant-1.3.2/lib/active_merchant/billing/gateways
# MANUAL https://www.paypal.com/en_US/pdf/PP_APIReference.pdf
# See also:
# http://jadedpixel.ligh... |
github | itteco/service_merchant | https://github.com/itteco/service_merchant | recurring_billing/lib/gateways/paypal.rb | Ruby | mit | 191 | master | 5,104 | module RecurringBilling
class PaypalGateway < RecurringBillingGateway
include Utils
# Returns :paypal
def code
:paypal
end
# Returns 'PayPal Website Payments Pro (US)'
def name
'PayPal Website Payments Pro (US)'
end
# Checks whether passed parameters of requested rec... |
github | itteco/service_merchant | https://github.com/itteco/service_merchant | recurring_billing/lib/gateways/authorize_net.rb | Ruby | mit | 191 | master | 4,644 | module RecurringBilling
class AuthorizeNetGateway < RecurringBillingGateway
include Utils
def code
:authorize_net
end
def name
'Authorize.net'
end
# Check if update is possible using specified arguments
def correct_update?(billing_id, amount, card, payment_options, recurring... |
github | itteco/service_merchant | https://github.com/itteco/service_merchant | tracker/demo.rb | Ruby | mit | 191 | master | 272 | #!/usr/bin/env ruby
# This is a smoke test for Tracker component
require 'tracker'
puts "Verifying models classes..."
Transaction
RecurringPaymentProfile
puts "Verifying DB..."
require 'test/connection'
Transaction.count
RecurringPaymentProfile.find :first
puts "All OK" |
github | itteco/service_merchant | https://github.com/itteco/service_merchant | tracker/tracker.rb | Ruby | mit | 191 | master | 348 | #TODO: Use auto-loading from activesupport
require 'rubygems'
require 'activerecord'
$: << File.dirname(__FILE__) + "/../vendor/money-1.7.1/lib"
require File.dirname(__FILE__) + '/lib/models/recurring_payment_profile'
require File.dirname(__FILE__) + '/lib/models/transaction'
require File.dirname(__FILE__) + '/lib/r... |
github | itteco/service_merchant | https://github.com/itteco/service_merchant | tracker/Rakefile | Ruby | mit | 191 | master | 890 | require 'rake'
require File.dirname(__FILE__) + '/tasks/schema'
require 'rake/testtask'
namespace :test do
Rake::TestTask.new(:remote_tracker) do |t|
t.pattern = 'test/remote/**/*_test.rb'
t.ruby_opts << '-rubygems'
t.verbose = true
end
desc "Run all remote tests"
task :remote => [:remote_tracker... |
github | itteco/service_merchant | https://github.com/itteco/service_merchant | tracker/tasks/schema.rb | Ruby | mit | 191 | master | 3,435 | namespace :tracker do
desc 'Create Tracker database tables'
task :create_tables => :connection do
ActiveRecord::Base.connection.create_table :tracker_recurring_payment_profiles, :force => true do |t|
t.column :gateway_reference, :string, :unique => true
t.column :gateway, ... |
github | itteco/service_merchant | https://github.com/itteco/service_merchant | tracker/test/connection.rb | Ruby | mit | 191 | master | 295 | # As we're not using Rails in tests, we have to establish DB conneciton ourselves
require 'rubygems'
gem 'activerecord'
require 'activerecord'
gem 'sqlite3-ruby'
ActiveRecord::Base.establish_connection(
:adapter => "sqlite3",
:database => (File.dirname(__FILE__) + "/../db/test.db")
) |
github | itteco/service_merchant | https://github.com/itteco/service_merchant | tracker/test/recurring_payment_profile.rb | Ruby | mit | 191 | master | 1,129 | require File.dirname(__FILE__) + '/test_helper'
class RandomRecurringProfileTest < Test::Unit::TestCase
def setup
cred = fixtures(:paypal)
assert @gw = RecurringBilling::PaypalGateway.new(cred)
@card = credit_card(number='4532130086825928')
end
def test_crud_recurring_payment
payment_options = ... |
github | itteco/service_merchant | https://github.com/itteco/service_merchant | tracker/test/test_helper.rb | Ruby | mit | 191 | master | 1,905 | #!/usr/bin/env ruby
require 'rubygems'
require 'test/unit'
require 'activesupport'
silence_warnings do
require 'active_merchant'
end
require File.dirname(__FILE__) + "/connection"
$: << File.dirname(__FILE__) + "/../" # Tracker root
require 'tracker'
# Turn off invalid certificate crashes
require 'openssl'
sile... |
github | itteco/service_merchant | https://github.com/itteco/service_merchant | tracker/test/remote/authorize_net_test.rb | Ruby | mit | 191 | master | 2,199 | require File.dirname(__FILE__) + '/../test_helper'
require "tracker"
class AuthorizeNetGatewayRemoteTest < Test::Unit::TestCase
def setup
credentials = fixtures(:authorize_net)
assert @gw = RecurringBilling::AuthorizeNetGateway.new(credentials)
@card = credit_card()
end
def test_crud_recurring_paym... |
github | itteco/service_merchant | https://github.com/itteco/service_merchant | tracker/test/remote/paypal_test.rb | Ruby | mit | 191 | master | 4,534 | require File.dirname(__FILE__) + '/../test_helper'
require "mocha"
require "tracker"
class PaypalRemoteTest < Test::Unit::TestCase
def setup
cred = fixtures(:paypal)
assert @gw = RecurringBilling::PaypalGateway.new(cred)
@card = credit_card()
@card2 = credit_card('4929838635250031', {:first_name =>... |
github | itteco/service_merchant | https://github.com/itteco/service_merchant | tracker/test/unit/recurring_payment_profile_test.rb | Ruby | mit | 191 | master | 2,130 | require File.dirname(__FILE__) + '/../test_helper'
require 'money'
class RecurringPaymentProfileTest < Test::Unit::TestCase
def setup
@profile = ::RecurringPaymentProfile.new
end
def test_net_money_assigns
@profile.net_money=Money.new(333, currency='CAD')
assert_equal 333, @profile.net_amount
... |
github | itteco/service_merchant | https://github.com/itteco/service_merchant | tracker/lib/recurring_billing_extension.rb | Ruby | mit | 191 | master | 4,573 | require File.dirname(__FILE__) + '/../../recurring_billing/lib/recurring_billing'
module RecurringBilling
class RecurringBillingGateway
# Create recurring payment AND store it
def create_with_persist(amount, card, payment_options={}, recurring_options={})
if payment_id = create_without_persist(amount,... |
github | itteco/service_merchant | https://github.com/itteco/service_merchant | tracker/lib/models/transaction.rb | Ruby | mit | 191 | master | 485 | class Transaction < ActiveRecord::Base
# We cannot just use `table_name_prefix = "tracker_"' because it uses broken
# cattr_accessor and applies to all ActiveRecord::Base descendants when
# tracker is loaded from Subscription Manager
def self.table_name_prefix
"tracker_"
end
belongs_to :recurring_payme... |
github | itteco/service_merchant | https://github.com/itteco/service_merchant | tracker/lib/models/recurring_payment_profile.rb | Ruby | mit | 191 | master | 4,615 | class RecurringPaymentProfile < ActiveRecord::Base
# We cannot just use `table_name_prefix = "tracker_"' because it uses broken
# cattr_accessor and applies to all ActiveRecord::Base descendants when
# tracker is loaded from Subscription Manager
def self.table_name_prefix
"tracker_"
end
has_many :transa... |
github | itteco/service_merchant | https://github.com/itteco/service_merchant | subscription_management/subscription_management.rb | Ruby | mit | 191 | master | 278 | #TODO: Use auto-loading from activesupport
require 'rubygems'
require 'activerecord'
require File.dirname(__FILE__) + '/lib/models/subscription'
require File.dirname(__FILE__) + '/lib/models/subscription_profile'
require File.dirname(__FILE__) + '/lib/subscription_management' |
github | itteco/service_merchant | https://github.com/itteco/service_merchant | subscription_management/Rakefile | Ruby | mit | 191 | master | 578 | require 'rake'
require File.dirname(__FILE__) + '/tasks/schema.rb'
require 'rake/testtask'
namespace :test do
Rake::TestTask.new(:remote_sm) do |t|
t.pattern = 'test/remote/**/*_test.rb'
t.ruby_opts << '-rubygems'
t.verbose = true
end
desc "Run all remote tests"
task :remote => [:remote_sm]
R... |
github | itteco/service_merchant | https://github.com/itteco/service_merchant | subscription_management/test/connection.rb | Ruby | mit | 191 | master | 306 | # As we're not using Rails in tests, we have to establish DB conneciton ourselves
require 'rubygems'
gem 'activerecord'
require 'activerecord'
gem 'sqlite3-ruby'
ActiveRecord::Base.establish_connection(
:adapter => "sqlite3",
:database => (File.dirname(__FILE__) + "/../../tracker/db/test.db")
) |
github | itteco/service_merchant | https://github.com/itteco/service_merchant | subscription_management/test/test_helper.rb | Ruby | mit | 191 | master | 1,895 | #!/usr/bin/env ruby
require 'rubygems'
require 'test/unit'
require 'activesupport'
silence_warnings do
require 'active_merchant'
end
require File.dirname(__FILE__) + "/connection"
require File.dirname(__FILE__) + '/../subscription_management'
# Turn off invalid certificate crashes
require 'openssl'
silence_warnin... |
github | itteco/service_merchant | https://github.com/itteco/service_merchant | subscription_management/test/remote/subscription_management_test.rb | Ruby | mit | 191 | master | 5,014 | require File.dirname(__FILE__) + '/../test_helper'
require 'money'
class SubscriptionManagementRemoteTest < Test::Unit::TestCase
def setup
@sm = ::SubscriptionManagement.new(
:tariff_plans_config => File.dirname(__FILE__) + '/../../samples/backpack.yml',
:taxes_config => Fil... |
github | itteco/service_merchant | https://github.com/itteco/service_merchant | subscription_management/test/unit/subscription_management_test.rb | Ruby | mit | 191 | master | 1,765 | require File.dirname(__FILE__) + '/../test_helper'
require 'money'
class SubscriptionManagementTest < Test::Unit::TestCase
def setup
@smc = SubscriptionManagement
end
def test_format_feature
feature = {'quantity' => 5, 'feature' => {'name'=> 'Quota', 'unit'=> 'Gigabyte'}}
assert_equal 'Quota: 5 Gi... |
github | itteco/service_merchant | https://github.com/itteco/service_merchant | subscription_management/samples/demo.rb | Ruby | mit | 191 | master | 503 | #!/usr/bin/ruby
#
# Demo of configuration file reading and parsing
require 'yaml'
PRESET_FILE = 'presets.yml'
# Reads settings from specified file with applied presets.yml
def read_settings(filename)
raw_config = [File.read(PRESET_FILE), File.read(filename)].join("\n")
YAML.load(raw_config)
end
Dir["*.yml"].each ... |
github | itteco/service_merchant | https://github.com/itteco/service_merchant | subscription_management/tasks/schema.rb | Ruby | mit | 191 | master | 2,463 | namespace :subscription do
desc 'Create Subscription management database tables'
task :create_tables => :connection do
ActiveRecord::Base.connection.create_table :subscriptions, :force => true do |t|
t.column :account_id, :string, :null => false
t.column :tariff_plan_id, ... |
github | itteco/service_merchant | https://github.com/itteco/service_merchant | subscription_management/lib/subscription_management.rb | Ruby | mit | 191 | master | 14,761 | require 'yaml'
require File.dirname(__FILE__) + '/../../recurring_billing/lib/recurring_billing'
require File.dirname(__FILE__) + '/../../tracker/tracker'
require 'rubygems'
require 'active_support/inflector'
#module SubscriptionManagement
# This class allows handling of user subscriptions for given merchant servic... |
github | itteco/service_merchant | https://github.com/itteco/service_merchant | subscription_management/lib/models/subscription.rb | Ruby | mit | 191 | master | 870 | class Subscription < ActiveRecord::Base
has_many :subscription_profiles
has_many :recurring_payment_profiles, :through => :subscription_profiles
# Returns billing amount (sum of net amount + taxes)
def billing_amount
self.net_amount + self.taxes_amount
end
# Recalculate price and taxes
#
# subsc... |
github | avinashbot/redd | https://github.com/avinashbot/redd | Guardfile | Ruby | mit | 191 | master | 223 | # frozen_string_literal: true
guard :rspec, cmd: 'bundle exec rspec -fp' do
watch(%r{^spec/.+_spec\.rb$})
watch(%r{^lib/(.+)\.rb}) { |m| "spec/lib/#{m[1]}_spec.rb" }
watch('spec/spec_helper.rb') { 'spec' }
end |
github | avinashbot/redd | https://github.com/avinashbot/redd | redd.gemspec | Ruby | mit | 191 | master | 1,472 | # frozen_string_literal: true
lib = File.expand_path('../lib', __FILE__)
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
require 'redd/version'
Gem::Specification.new do |spec| # rubocop:disable Metrics/BlockLength
spec.name = 'redd'
spec.version = Redd::VERSION
spec.authors = ['Avinash Dwarapu']
... |
github | avinashbot/redd | https://github.com/avinashbot/redd | Rakefile | Ruby | mit | 191 | master | 243 | # frozen_string_literal: true
require 'bundler/gem_tasks'
require 'rubocop/rake_task'
require 'rspec/core/rake_task'
RuboCop::RakeTask.new do |t|
t.fail_on_error = false
end
RSpec::Core::RakeTask.new(:spec)
task default: %i[rubocop spec] |
github | avinashbot/redd | https://github.com/avinashbot/redd | lib/redd.rb | Ruby | mit | 191 | master | 5,219 | # frozen_string_literal: true
require 'uri'
# Redd Version
require_relative 'redd/version'
# Models
Dir[File.join(__dir__, 'redd', 'models', '*.rb')].each { |f| require f }
# Authentication Clients
Dir[File.join(__dir__, 'redd', 'auth_strategies', '*.rb')].each { |f| require f }
# Error Classes
require_relative 'redd... |
github | avinashbot/redd | https://github.com/avinashbot/redd | lib/redd/client.rb | Ruby | mit | 191 | master | 3,156 | # frozen_string_literal: true
require 'http'
require 'json'
module Redd
# The base class for JSON-based HTTP clients. Generic enough to be used for basically anything.
class Client
# The default User-Agent to use if none was provided.
USER_AGENT = "Ruby:Redd:v#{Redd::VERSION} (by unknown)"
# Holds a ... |
github | avinashbot/redd | https://github.com/avinashbot/redd | lib/redd/errors.rb | Ruby | mit | 191 | master | 1,959 | # frozen_string_literal: true
module Redd
# Namespace for Redd errors.
module Errors
# An error raised by {Redd::Middleware} when there was an error returned by reddit.
class TokenRetrievalError < StandardError; end
# An error with the API.
class APIError < StandardError
attr_reader :respons... |
github | avinashbot/redd | https://github.com/avinashbot/redd | lib/redd/api_client.rb | Ruby | mit | 191 | master | 3,892 | # frozen_string_literal: true
require_relative 'client'
require_relative 'utilities/error_handler'
require_relative 'utilities/rate_limiter'
require_relative 'utilities/unmarshaller'
module Redd
# The class for API clients.
class APIClient < Client
# The endpoint to make API requests to.
API_ENDPOINT = 'h... |
github | avinashbot/redd | https://github.com/avinashbot/redd | lib/redd/middleware.rb | Ruby | mit | 191 | master | 4,961 | # frozen_string_literal: true
require 'rack'
require 'securerandom'
require_relative '../redd'
module Redd
# Rack middleware.
class Middleware
# @param opts [Hash] the options to create the object with
# @option opts [String] :user_agent your app's *unique* and *descriptive* user agent
# @option opts... |
github | avinashbot/redd | https://github.com/avinashbot/redd | lib/redd/auth_strategies/web.rb | Ruby | mit | 191 | master | 1,277 | # frozen_string_literal: true
require_relative 'auth_strategy'
module Redd
module AuthStrategies
# A typical code-based authentication, for 'web' and 'installed' types.
class Web < AuthStrategy
def initialize(client_id:, redirect_uri:, secret: '', **kwargs)
super(client_id: client_id, secret: ... |
github | avinashbot/redd | https://github.com/avinashbot/redd | lib/redd/auth_strategies/userless.rb | Ruby | mit | 191 | master | 729 | # frozen_string_literal: true
require_relative 'auth_strategy'
module Redd
module AuthStrategies
# A userless authentication scheme.
class Userless < AuthStrategy
# Perform authentication and return the resulting access object
# @return [Access] the access token object
def authenticate
... |
github | avinashbot/redd | https://github.com/avinashbot/redd | lib/redd/auth_strategies/auth_strategy.rb | Ruby | mit | 191 | master | 2,278 | # frozen_string_literal: true
require_relative '../client'
module Redd
module AuthStrategies
# The API client for authentication to reddit.
class AuthStrategy < Client
# The API to make authentication requests to.
AUTH_ENDPOINT = 'https://www.reddit.com'
# @param client_id [String] the cl... |
github | avinashbot/redd | https://github.com/avinashbot/redd | lib/redd/auth_strategies/script.rb | Ruby | mit | 191 | master | 991 | # frozen_string_literal: true
require_relative 'auth_strategy'
module Redd
module AuthStrategies
# A password-based authentication scheme. Requests all scopes.
class Script < AuthStrategy
def initialize(client_id:, secret:, username:, password:, **kwargs)
super(client_id: client_id, secret: se... |
github | avinashbot/redd | https://github.com/avinashbot/redd | lib/redd/assist/delete_badly_scoring.rb | Ruby | mit | 191 | master | 2,246 | # frozen_string_literal: true
module Redd
module Assist
# Helper class for deleting negative links or comments. You can run this as a separate process,
# as long as you set your rate limit time higher in your main process.
# @note Works with {Submission} and {Comment}.
# @example
# assist = Red... |
github | avinashbot/redd | https://github.com/avinashbot/redd | lib/redd/utilities/error_handler.rb | Ruby | mit | 191 | master | 2,489 | # frozen_string_literal: true
require_relative '../errors'
module Redd
module Utilities
# Handles response errors in API responses.
class ErrorHandler
AUTH_HEADER = 'www-authenticate'
INVALID_TOKEN = 'invalid_token'
INSUFFICIENT_SCOPE = 'insufficient_scope'
HTTP_ERRORS =... |
github | avinashbot/redd | https://github.com/avinashbot/redd | lib/redd/utilities/unmarshaller.rb | Ruby | mit | 191 | master | 2,192 | # frozen_string_literal: true
module Redd
module Utilities
# Unmarshals hashes into objects.
class Unmarshaller
# Contains the mapping from 'kind' strings to classes.
# TODO: UserList type!
MAPPING = {
'Listing' => Models::Listing,
't1' => Models::Comment,
... |
github | avinashbot/redd | https://github.com/avinashbot/redd | lib/redd/utilities/rate_limiter.rb | Ruby | mit | 191 | master | 459 | # frozen_string_literal: true
module Redd
module Utilities
# Manages rate limiting by sleeping.
class RateLimiter
def initialize(gap)
@gap = gap
@last_request_time = Time.now - gap
end
def after_limit
sleep_time = (@last_request_time + @gap) - Time.now
sleep... |
github | avinashbot/redd | https://github.com/avinashbot/redd | lib/redd/models/paginated_listing.rb | Ruby | mit | 191 | master | 3,846 | # frozen_string_literal: true
require_relative 'model'
module Redd
module Models
# An enumerable type that covers listings and expands forwards.
#
# If you want to use the #[] operator, you'll need to convert the object to an Array. This can
# be done with either {Enumerable#first} or {Enumerable#to... |
github | avinashbot/redd | https://github.com/avinashbot/redd | lib/redd/models/access.rb | Ruby | mit | 191 | master | 1,855 | # frozen_string_literal: true
require_relative 'model'
module Redd
module Models
# Models access_token and related keys.
# @note This model also supports an additional key, called `:created_at` which is a UNIX time
# representing the time the access was created. The default value is the time the objec... |
github | avinashbot/redd | https://github.com/avinashbot/redd | lib/redd/models/multireddit.rb | Ruby | mit | 191 | master | 3,522 | # frozen_string_literal: true
require_relative 'model'
module Redd
module Models
# A multi.
class Multireddit < Model
# Get the appropriate listing.
# @param sort [:hot, :new, :top, :controversial, :comments, :rising, :gilded] the type of
# listing
# @param params [Hash] a list of ... |
github | avinashbot/redd | https://github.com/avinashbot/redd | lib/redd/models/model.rb | Ruby | mit | 191 | master | 478 | # frozen_string_literal: true
require 'lazy_lazer'
module Redd
module Models
# A base model class.
class Model
include LazyLazer
# @return [Client] the model's client
attr_reader :client
# Create a new Model.
# @param client [Client] the model's client
# @param attribut... |
github | avinashbot/redd | https://github.com/avinashbot/redd | lib/redd/models/mod_action.rb | Ruby | mit | 191 | master | 1,883 | # frozen_string_literal: true
require_relative 'model'
module Redd
module Models
# Represents a moderator action, part of a moderation log.
# @see Subreddit#mod_log
class ModAction < Model
# @!attribute [r] description
# @return [String] the action description
property :description
... |
github | avinashbot/redd | https://github.com/avinashbot/redd | lib/redd/models/private_message.rb | Ruby | mit | 191 | master | 3,087 | # frozen_string_literal: true
require_relative 'model'
require_relative 'inboxable'
require_relative 'replyable'
require_relative 'reportable'
module Redd
module Models
# A private message
class PrivateMessage < Model
include Inboxable
include Replyable
include Reportable
# Delete t... |
github | avinashbot/redd | https://github.com/avinashbot/redd | lib/redd/models/modmail.rb | Ruby | mit | 191 | master | 2,459 | # frozen_string_literal: true
require_relative 'model'
require_relative 'subreddit'
module Redd
module Models
# A container for the new modmail.
class Modmail < Model
# @return [Hash<Symbol, Integer>] the number of unread messages in each category
def unread_count
client.get('/api/mod/co... |
github | avinashbot/redd | https://github.com/avinashbot/redd | lib/redd/models/submission.rb | Ruby | mit | 191 | master | 13,654 | # frozen_string_literal: true
require_relative 'model'
require_relative 'gildable'
require_relative 'moderatable'
require_relative 'postable'
require_relative 'replyable'
require_relative 'reportable'
require_relative 'user'
require_relative 'subreddit'
module Redd
module Models
# A text or link post.
clas... |
github | avinashbot/redd | https://github.com/avinashbot/redd | lib/redd/models/user.rb | Ruby | mit | 191 | master | 8,956 | # frozen_string_literal: true
require_relative 'model'
require_relative 'messageable'
module Redd
module Models
# A reddit user.
class User < Model
include Messageable
# Get the appropriate listing.
# @param type [:overview, :submitted, :comments, :liked, :disliked, :hidden, :saved, :gild... |
github | avinashbot/redd | https://github.com/avinashbot/redd | lib/redd/models/wiki_page.rb | Ruby | mit | 191 | master | 1,802 | # frozen_string_literal: true
require_relative 'model'
module Redd
module Models
# A reddit user.
class WikiPage < Model
# Edit the wiki page.
# @param content [String] the new wiki page contents
# @param reason [String, nil] an optional reason for editing the page
def edit(content, ... |
github | avinashbot/redd | https://github.com/avinashbot/redd | lib/redd/models/listing.rb | Ruby | mit | 191 | master | 1,546 | # frozen_string_literal: true
require_relative 'model'
module Redd
module Models
# A backward-expading listing of items.
# @see Stream
class Listing < Model
include Enumerable
# Create an empty listing with a client.
# @param client [APIClient] the client to create the listing with
... |
github | avinashbot/redd | https://github.com/avinashbot/redd | lib/redd/models/session.rb | Ruby | mit | 191 | master | 7,088 | # frozen_string_literal: true
require_relative 'model'
require_relative 'searchable'
module Redd
module Models
# The starter class.
class Session < Model
include Searchable
# @return [User] the logged-in user
def me
@me ||= Self.new(client)
end
# @return [FrontPage] t... |
github | avinashbot/redd | https://github.com/avinashbot/redd | lib/redd/models/reportable.rb | Ruby | mit | 191 | master | 344 | # frozen_string_literal: true
module Redd
module Models
# Things that can be reported (except users).
module Reportable
# Report the object.
# @param reason [String] the report reason
def report(reason)
client.post('/api/report', thing_id: read_attribute(:name), reason: reason)
... |
github | avinashbot/redd | https://github.com/avinashbot/redd | lib/redd/models/self.rb | Ruby | mit | 191 | master | 278 | # frozen_string_literal: true
require_relative 'user'
module Redd
module Models
# The user that the bot is running under.
class Self < User
private
def lazer_reload
fully_loaded!
client.get('/api/v1/me').body
end
end
end
end |
github | avinashbot/redd | https://github.com/avinashbot/redd | lib/redd/models/messageable.rb | Ruby | mit | 191 | master | 748 | # frozen_string_literal: true
module Redd
module Models
# A model that can be messaged (i.e. Users and Subreddits).
module Messageable
# Compose a message to a person or the moderators of a subreddit.
#
# @param to [String] the thing to send the message to (overriden by User and Subreddit)
... |
github | avinashbot/redd | https://github.com/avinashbot/redd | lib/redd/models/modmail_message.rb | Ruby | mit | 191 | master | 895 | # frozen_string_literal: true
require 'time'
require_relative 'model'
module Redd
module Models
# Represents a message in the new modmail.
class ModmailMessage < Model
# @!attribute [r] id
# @return [String] the message id
property :id
# @!attribute [r] body
# @return [Str... |
github | avinashbot/redd | https://github.com/avinashbot/redd | lib/redd/models/subreddit.rb | Ruby | mit | 191 | master | 26,943 | # frozen_string_literal: true
require_relative 'model'
require_relative 'messageable'
require_relative 'searchable'
module Redd
module Models
# A subreddit.
class Subreddit < Model
include Messageable
include Searchable
# A mapping from keys returned by #settings to keys required by #modi... |
github | avinashbot/redd | https://github.com/avinashbot/redd | lib/redd/models/gildable.rb | Ruby | mit | 191 | master | 294 | # frozen_string_literal: true
module Redd
module Models
# A model that can be gilded.
module Gildable
# Gift a user one month of reddit gold for their link or comment.
def gild
client.post("/api/v1/gold/gild/#{read_attribute(:name)}")
end
end
end
end |
github | avinashbot/redd | https://github.com/avinashbot/redd | lib/redd/models/front_page.rb | Ruby | mit | 191 | master | 1,966 | # frozen_string_literal: true
require_relative 'model'
module Redd
module Models
# The front page.
# FIXME: deal with serious code duplication from Subreddit
class FrontPage < Model
# @return [Array<String>] reddit's base wiki pages
def wiki_pages
client.get('/wiki/pages').body[:data... |
github | avinashbot/redd | https://github.com/avinashbot/redd | lib/redd/models/modmail_conversation.rb | Ruby | mit | 191 | master | 4,730 | # frozen_string_literal: true
require 'time'
require_relative 'model'
module Redd
module Models
# Represents a conversation in the new modmail.
class ModmailConversation < Model
# Add a reply to the ongoing conversation.
# @param body [String] the message body (probably markdown)
# @param ... |
github | avinashbot/redd | https://github.com/avinashbot/redd | lib/redd/models/more_comments.rb | Ruby | mit | 191 | master | 3,154 | # frozen_string_literal: true
require_relative 'model'
module Redd
module Models
# An object that represents a bunch of comments that need to be expanded.
class MoreComments < Model
# Expand the object's children into a listing of Comments and MoreComments.
# @param link [Submission] the submiss... |
github | avinashbot/redd | https://github.com/avinashbot/redd | lib/redd/models/postable.rb | Ruby | mit | 191 | master | 2,206 | # frozen_string_literal: true
module Redd
module Models
# Methods for user-submitted content, i.e. Submissions and Comments.
module Postable
# Edit a thing.
# @param text [String] The new text.
# @return [self] the edited thing
def edit(text)
client.post('/api/editusertext', t... |
github | avinashbot/redd | https://github.com/avinashbot/redd | lib/redd/models/comment.rb | Ruby | mit | 191 | master | 7,591 | # frozen_string_literal: true
require_relative 'model'
require_relative 'gildable'
require_relative 'inboxable'
require_relative 'moderatable'
require_relative 'postable'
require_relative 'replyable'
require_relative 'reportable'
require_relative 'listing'
require_relative 'subreddit'
require_relative 'user'
module ... |
github | avinashbot/redd | https://github.com/avinashbot/redd | lib/redd/models/moderatable.rb | Ruby | mit | 191 | master | 1,532 | # frozen_string_literal: true
module Redd
module Models
# A model that can be managed by a moderator (i.e. Submissions and Comments).
module Moderatable
# Approve a submission.
def approve
client.post('/api/approve', id: read_attribute(:name))
end
# Remove a submission.
... |
github | avinashbot/redd | https://github.com/avinashbot/redd | lib/redd/models/replyable.rb | Ruby | mit | 191 | master | 492 | # frozen_string_literal: true
module Redd
module Models
# A model that can be commented on or replied to.
module Replyable
# Add a comment to a link, reply to a comment or reply to a message.
# @param text [String] the text to comment
# @return [Comment, PrivateMessage] The created reply.
... |
github | avinashbot/redd | https://github.com/avinashbot/redd | lib/redd/models/live_thread.rb | Ruby | mit | 191 | master | 4,850 | # frozen_string_literal: true
require_relative 'model'
module Redd
module Models
# Represents a live thread.
class LiveThread < Model
# Get the updates from the thread.
# @param params [Hash] a list of params to send with the request
# @option params [String] :after return results after th... |
github | avinashbot/redd | https://github.com/avinashbot/redd | lib/redd/models/live_update.rb | Ruby | mit | 191 | master | 1,234 | # frozen_string_literal: true
require_relative 'model'
module Redd
module Models
# A live thread update.
class LiveUpdate < Model
# @!attribute [r] id
# @return [String] the update id
property :id, :required
# @!attribute [r] name
# @return [String] the update fullname
... |
github | avinashbot/redd | https://github.com/avinashbot/redd | lib/redd/models/inboxable.rb | Ruby | mit | 191 | master | 828 | # frozen_string_literal: true
module Redd
module Models
# Things that can be sent to a user's inbox.
module Inboxable
# Block the user that sent this item.
def block
client.post('/api/block', id: read_attribute(:name))
end
# Collapse the item.
def collapse
clien... |
github | avinashbot/redd | https://github.com/avinashbot/redd | lib/redd/models/searchable.rb | Ruby | mit | 191 | master | 1,544 | # frozen_string_literal: true
module Redd
module Models
# Applied to {Session} for site-wide and {Subreddit} for subreddit-specific search.
module Searchable
# Search reddit.
# @see https://www.reddit.com/wiki/search
#
# @param query [String] the search query
# @param params [Ha... |
github | avinashbot/redd | https://github.com/avinashbot/redd | lib/redd/models/trophy.rb | Ruby | mit | 191 | master | 816 | # frozen_string_literal: true
require_relative 'model'
module Redd
module Models
# A user trophy.
class Trophy < Model
# @!attribute [r] icon_70px
# @return [String] the url for a 70x70 thumbnail icon
property :icon_70px, from: :icon_70
# @!attribute [r] icon_40px
# @retur... |
github | avinashbot/redd | https://github.com/avinashbot/redd | spec/spec_helper.rb | Ruby | mit | 191 | master | 740 | # frozen_string_literal: true
require 'simplecov'
SimpleCov.start
require 'webmock/rspec'
WebMock.disable_net_connect!
require_relative '../lib/redd'
require_relative 'support/api_helpers'
RSpec.configure do |config|
config.include APIHelpers
config.expect_with :rspec do |expectations|
expectations.include... |
github | avinashbot/redd | https://github.com/avinashbot/redd | spec/redd_spec.rb | Ruby | mit | 191 | master | 1,577 | # frozen_string_literal: true
RSpec.describe Redd do
describe '.it' do
it 'returns a Session' do
expect_any_instance_of(Redd::AuthStrategies::Script).to receive(:authenticate)
session = Redd.it(client_id: '', secret: '', username: '', password: '')
expect(session).to be_a(Redd::Models::Session)... |
github | avinashbot/redd | https://github.com/avinashbot/redd | spec/redd/client_spec.rb | Ruby | mit | 191 | master | 1,618 | # frozen_string_literal: true
require 'webmock/rspec'
RSpec.describe Redd::Client do
before do
WebMock.disable_net_connect!
end
describe '#get' do
it 'makes a GET request' do
request = stub_request(:get, 'https://test.com/get_request').with(query: { 'param' => '1' })
Redd::Client.new(endpoi... |
github | avinashbot/redd | https://github.com/avinashbot/redd | spec/redd/api_client_spec.rb | Ruby | mit | 191 | master | 2,362 | # frozen_string_literal: true
RSpec.describe Redd::APIClient do
describe '#authenticate' do
it 'calls #authenticate on the auth strategy with a given code' do
auth_strategy = instance_double('Redd::AuthStrategies::AuthStrategy')
expect(auth_strategy).to receive(:authenticate).with('some-code')
... |
github | avinashbot/redd | https://github.com/avinashbot/redd | spec/support/stub_client.rb | Ruby | mit | 191 | master | 618 | # frozen_string_literal: true
require 'redd/utilities/unmarshaller'
class StubClient
# Holds a returned HTTP response.
Response = Struct.new(:code, :headers, :body) do
def raw_body
@raw_body ||= JSON.generate(body)
end
end
def initialize
@unmarshaller = Redd::Utilities::Unmarshaller.new(sel... |
github | avinashbot/redd | https://github.com/avinashbot/redd | spec/support/api_helpers.rb | Ruby | mit | 191 | master | 482 | # frozen_string_literal: true
require_relative 'stub_client'
module APIHelpers
def client
StubClient.new
end
def stub_api(verb, path, params = {}, &block)
if params.empty?
allow_any_instance_of(StubClient).to receive(verb, &block).with(path)
else
allow_any_instance_of(StubClient).to rec... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.