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 | flyerhzm/activemerchant_patch_for_china | https://github.com/flyerhzm/activemerchant_patch_for_china | lib/active_merchant/billing/integrations/bill99.rb | Ruby | mit | 304 | master | 539 | require File.dirname(__FILE__) + '/bill99/helper.rb'
require File.dirname(__FILE__) + '/bill99/return.rb'
module ActiveMerchant #:nodoc:
module Billing #:nodoc:
module Integrations #:nodoc:
module Bill99
mattr_accessor :service_url
self.service_url = 'https://www.99bill.com/gateway/receive... |
github | flyerhzm/activemerchant_patch_for_china | https://github.com/flyerhzm/activemerchant_patch_for_china | lib/active_merchant/billing/integrations/tenpay/helper.rb | Ruby | mit | 304 | master | 1,189 | require 'digest/md5'
module ActiveMerchant #:nodoc:
module Billing #:nodoc:
module Integrations #:nodoc:
module Tenpay
class Helper < ActiveMerchant::Billing::Integrations::Helper
# Replace with the real mapping
mapping :account, 'bargainor_id'
mapping :amount, 'total_... |
github | flyerhzm/activemerchant_patch_for_china | https://github.com/flyerhzm/activemerchant_patch_for_china | lib/active_merchant/billing/integrations/tenpay/return.rb | Ruby | mit | 304 | master | 1,228 | require 'digest/md5'
module ActiveMerchant #:nodoc:
module Billing #:nodoc:
module Integrations #:nodoc:
module Tenpay
class Return < ActiveMerchant::Billing::Integrations::Return
def account
@params["bargainor_id"]
end
def order
@params["sp_b... |
github | flyerhzm/activemerchant_patch_for_china | https://github.com/flyerhzm/activemerchant_patch_for_china | lib/active_merchant/billing/integrations/alipay/helper.rb | Ruby | mit | 304 | master | 3,444 | require 'cgi'
require 'digest/md5'
module ActiveMerchant #:nodoc:
module Billing #:nodoc:
module Integrations #:nodoc:
module Alipay
class Helper < ActiveMerchant::Billing::Integrations::Helper
CREATE_DIRECT_PAY_BY_USER = 'create_direct_pay_by_user'
CREATE_PARTNER_TRADE_BY_BUYER... |
github | flyerhzm/activemerchant_patch_for_china | https://github.com/flyerhzm/activemerchant_patch_for_china | lib/active_merchant/billing/integrations/alipay/return.rb | Ruby | mit | 304 | master | 760 | require 'active_merchant/billing/integrations/alipay/sign.rb'
module ActiveMerchant #:nodoc:
module Billing #:nodoc:
module Integrations #:nodoc:
module Alipay
class Return < ActiveMerchant::Billing::Integrations::Return
include Sign
def order
@params["out_trade_no"... |
github | flyerhzm/activemerchant_patch_for_china | https://github.com/flyerhzm/activemerchant_patch_for_china | lib/active_merchant/billing/integrations/alipay/notification.rb | Ruby | mit | 304 | master | 2,531 | require 'net/http'
require 'active_merchant/billing/integrations/alipay/sign'
module ActiveMerchant #:nodoc:
module Billing #:nodoc:
module Integrations #:nodoc:
module Alipay
class Notification < ActiveMerchant::Billing::Integrations::Notification
include Sign
def complete?
... |
github | flyerhzm/activemerchant_patch_for_china | https://github.com/flyerhzm/activemerchant_patch_for_china | lib/active_merchant/billing/integrations/alipay/sign.rb | Ruby | mit | 304 | master | 639 | require 'digest/md5'
require 'cgi'
module ActiveMerchant #:nodoc:
module Billing #:nodoc:
module Integrations #:nodoc:
module Alipay
module Sign
def verify_sign
sign_type = @params.delete("sign_type")
sign = @params.delete("sign")
md5_string = @params.... |
github | flyerhzm/activemerchant_patch_for_china | https://github.com/flyerhzm/activemerchant_patch_for_china | lib/active_merchant/billing/integrations/bill99/helper.rb | Ruby | mit | 304 | master | 1,008 | require 'digest/md5'
module ActiveMerchant #:nodoc:
module Billing #:nodoc:
module Integrations #:nodoc:
module Bill99
class Helper < ActiveMerchant::Billing::Integrations::Helper
mapping :account, 'merchant_id'
mapping :amount, 'amount'
mapping :currency, 'currency'
... |
github | flyerhzm/activemerchant_patch_for_china | https://github.com/flyerhzm/activemerchant_patch_for_china | lib/active_merchant/billing/integrations/bill99/notification.rb | Ruby | mit | 304 | master | 1,574 | require 'net/http'
module ActiveMerchant #:nodoc:
module Billing #:nodoc:
module Integrations #:nodoc:
module Bill99
class Notification < ActiveMerchant::Billing::Integrations::Notification
def complete?
"10" == params["payResult"]
end
def received_at
... |
github | flyerhzm/activemerchant_patch_for_china | https://github.com/flyerhzm/activemerchant_patch_for_china | lib/active_merchant/billing/integrations/bill99/return.rb | Ruby | mit | 304 | master | 1,275 | require 'digest/md5'
module ActiveMerchant #:nodoc:
module Billing #:nodoc:
module Integrations #:nodoc:
module Bill99
class Return < ActiveMerchant::Billing::Integrations::Return
def account
@params["merchant_id"]
end
def order
@params["order... |
github | flyerhzm/activemerchant_patch_for_china | https://github.com/flyerhzm/activemerchant_patch_for_china | lib/active_merchant/billing/integrations/yeepay/notification.rb | Ruby | mit | 304 | master | 1,366 | module ActiveMerchant #:nodoc:
module Billing #:nodoc:
module Integrations #:nodoc:
module Yeepay
class Notification < ActiveMerchant::Billing::Integrations::Notification
def complete?
"1" == params["r1_Code"]
end
def received_at
Time.parse para... |
github | flyerhzm/activemerchant_patch_for_china | https://github.com/flyerhzm/activemerchant_patch_for_china | lib/active_merchant/billing/integrations/yeepay/return.rb | Ruby | mit | 304 | master | 531 | module ActiveMerchant #:nodoc:
module Billing #:nodoc:
module Integrations #:nodoc:
module Yeepay
class Return < ActiveMerchant::Billing::Integrations::Return
def success?
hmac_md5_hexdigest == params['hmac']
end
private
def hmac_md5_hexdigest
... |
github | flyerhzm/activemerchant_patch_for_china | https://github.com/flyerhzm/activemerchant_patch_for_china | lib/active_merchant/billing/integrations/yeepay/helper.rb | Ruby | mit | 304 | master | 891 | require 'openssl'
module ActiveMerchant #:nodoc:
module Billing #:nodoc:
module Integrations #:nodoc:
module Yeepay
class Helper < ActiveMerchant::Billing::Integrations::Helper
mapping :account, 'p1_MerId'
mapping :order, 'p2_Order'
mapping :amount, 'p3_Amt'
... |
github | flyerhzm/activemerchant_patch_for_china | https://github.com/flyerhzm/activemerchant_patch_for_china | lib/active_merchant/billing/integrations/pay19/helper.rb | Ruby | mit | 304 | master | 1,220 | require 'digest/md5'
module ActiveMerchant #:nodoc:
module Billing #:nodoc:
module Integrations #:nodoc:
module Pay19
class Helper < ActiveMerchant::Billing::Integrations::Helper
mapping :account, 'merchant_id'
mapping :amount, 'amount'
mapping :currency, 'currency'
... |
github | flyerhzm/activemerchant_patch_for_china | https://github.com/flyerhzm/activemerchant_patch_for_china | lib/active_merchant/billing/integrations/pay19/notification.rb | Ruby | mit | 304 | master | 1,430 | require 'net/http'
module ActiveMerchant #:nodoc:
module Billing #:nodoc:
module Integrations #:nodoc:
module Pay19
class Notification < ActiveMerchant::Billing::Integrations::Notification
def complete?
"Y" == params["result"]
end
def received_at
... |
github | flyerhzm/activemerchant_patch_for_china | https://github.com/flyerhzm/activemerchant_patch_for_china | lib/active_merchant/billing/integrations/pay19/return.rb | Ruby | mit | 304 | master | 1,529 | require 'digest/md5'
module ActiveMerchant #:nodoc:
module Billing #:nodoc:
module Integrations #:nodoc:
module Pay19
class Return < ActiveMerchant::Billing::Integrations::Return
def account
@params["merchant_id"]
end
def order
@params["order_... |
github | flyerhzm/activemerchant_patch_for_china | https://github.com/flyerhzm/activemerchant_patch_for_china | lib/active_merchant/billing/integrations/bill99_card/helper.rb | Ruby | mit | 304 | master | 1,565 | require 'digest/md5'
module ActiveMerchant #:nodoc:
module Billing #:nodoc:
module Integrations #:nodoc:
module Bill99Card
class Helper < ActiveMerchant::Billing::Integrations::Helper
mapping :account, 'merchantAcctId'
mapping :amount, 'orderAmount'
mapping :order, 'or... |
github | flyerhzm/activemerchant_patch_for_china | https://github.com/flyerhzm/activemerchant_patch_for_china | lib/active_merchant/billing/integrations/bill99_card/notification.rb | Ruby | mit | 304 | master | 1,619 | require 'net/http'
module ActiveMerchant #:nodoc:
module Billing #:nodoc:
module Integrations #:nodoc:
module Bill99Card
class Notification < ActiveMerchant::Billing::Integrations::Notification
def complete?
"10" == params["payResult"]
end
def received_at
... |
github | flyerhzm/activemerchant_patch_for_china | https://github.com/flyerhzm/activemerchant_patch_for_china | lib/active_merchant/billing/integrations/bill99_card/return.rb | Ruby | mit | 304 | master | 1,390 | require 'digest/md5'
module ActiveMerchant #:nodoc:
module Billing #:nodoc:
module Integrations #:nodoc:
module Bill99Card
class Return < ActiveMerchant::Billing::Integrations::Return
def account
params["merchantAcctId"]
end
def order
params["... |
github | seamusabshere/data_miner | https://github.com/seamusabshere/data_miner | data_miner.gemspec | Ruby | mit | 304 | master | 2,369 | # -*- encoding: utf-8 -*-
require File.expand_path("../lib/data_miner/version", __FILE__)
Gem::Specification.new do |s|
s.name = "data_miner"
s.version = DataMiner::VERSION
s.authors = ["Seamus Abshere", "Andy Rossmeissl", "Derek Kastner", "Ian Hough", "Tower He"]
s.email = ["seamus@absher... |
github | seamusabshere/data_miner | https://github.com/seamusabshere/data_miner | Rakefile | Ruby | mit | 304 | master | 1,006 | #!/usr/bin/env rake
require "bundler/gem_tasks"
require 'rake'
require 'rake/testtask'
Rake::TestTask.new(:test) do |test|
test.libs << 'test'
test.pattern = 'test/**/test_*.rb'
test.verbose = true
end
task :test_separately do
Dir[File.expand_path('../test/**/test_*.rb', __FILE__)].each do |path|
sleep 0.... |
github | seamusabshere/data_miner | https://github.com/seamusabshere/data_miner | lib/data_miner.rb | Ruby | mit | 304 | master | 2,745 | require 'singleton'
require 'set'
require 'date'
require 'active_support'
require 'active_support/version'
if ::ActiveSupport::VERSION::MAJOR >= 3
require 'active_support/core_ext'
end
require 'active_record'
if RUBY_VERSION >= '1.9'
begin
require 'unicode_utils/downcase'
rescue LoadError
# oh well.
end... |
github | seamusabshere/data_miner | https://github.com/seamusabshere/data_miner | lib/data_miner/attribute.rb | Ruby | mit | 304 | master | 9,744 | class DataMiner
# A mapping between a local model column and a remote data source column.
#
# @see DataMiner::ActiveRecordClassMethods#data_miner Overview of how to define data miner scripts inside of ActiveRecord models.
# @see DataMiner::Step::Import#store Telling an import step to store a column with DataMin... |
github | seamusabshere/data_miner | https://github.com/seamusabshere/data_miner | lib/data_miner/step.rb | Ruby | mit | 304 | master | 430 | class DataMiner
class Step
# @private
attr_reader :script
# @private
def ==(other)
other.class == self.class and other.description == description
end
# @private
def model
script.model
end
def pos
script.steps.index self
end
def register(step)
# n... |
github | seamusabshere/data_miner | https://github.com/seamusabshere/data_miner | lib/data_miner/script.rb | Ruby | mit | 304 | master | 10,076 | class DataMiner
# The container that holds each step in the script.
class Script
class << self
# @private
# activerecord-3.2.3/lib/active_record/scoping.rb
def uniq
previous_uniq = current_uniq
Script.current_uniq = true
begin
yield
ensure
Sc... |
github | seamusabshere/data_miner | https://github.com/seamusabshere/data_miner | lib/data_miner/active_record_class_methods.rb | Ruby | mit | 304 | master | 3,483 | require 'active_record'
class DataMiner
# Class methods that are mixed into models (i.e. ActiveRecord::Base)
module ActiveRecordClassMethods
# Access this model's script.
#
# @return [DataMiner::Script] This model's data miner script.
def data_miner_script
@data_miner_script || ::Thread.exclu... |
github | seamusabshere/data_miner | https://github.com/seamusabshere/data_miner | lib/data_miner/step/import.rb | Ruby | mit | 304 | master | 7,988 | require 'errata'
require 'remote_table'
require 'upsert'
class DataMiner
class Step
# A step that imports data from a remote source.
#
# Create these by calling +import+ inside a +data_miner+ block.
#
# @see DataMiner::ActiveRecordClassMethods#data_miner Overview of how to define data miner scrip... |
github | seamusabshere/data_miner | https://github.com/seamusabshere/data_miner | lib/data_miner/step/process.rb | Ruby | mit | 304 | master | 1,505 | class DataMiner
class Step
# A step that executes a single class method on the model or an arbitrary code block.
#
# Create these by calling +process+ inside a +data_miner+ block.
#
# @see DataMiner::ActiveRecordClassMethods#data_miner Overview of how to define data miner scripts inside of ActiveR... |
github | seamusabshere/data_miner | https://github.com/seamusabshere/data_miner | lib/data_miner/step/test.rb | Ruby | mit | 304 | master | 2,171 | require 'rspec-expectations'
class DataMiner
class Step
# A step that runs tests and stops the data miner on failures.
#
# Create these by calling +test+ inside a +data_miner+ block.
#
# @see DataMiner::ActiveRecordClassMethods#data_miner Overview of how to define data miner scripts inside of Act... |
github | seamusabshere/data_miner | https://github.com/seamusabshere/data_miner | lib/data_miner/step/sql.rb | Ruby | mit | 304 | master | 3,668 | require 'csv'
require 'tmpdir'
require 'posix/spawn'
require 'unix_utils'
class DataMiner
class Step
# A step that executes a SQL, either from a string or as retrieved from a URL.
#
# Create these by calling +sql+ inside a +data_miner+ block.
#
# @see DataMiner::ActiveRecordClassMethods#data_mine... |
github | seamusabshere/data_miner | https://github.com/seamusabshere/data_miner | test/test_data_miner.rb | Ruby | mit | 304 | master | 4,122 | # -*- encoding: utf-8 -*-
require 'helper'
init_database
init_models
describe DataMiner do
describe "when used to import example data about pets" do
before do
Pet.delete_all
Pet2.delete_all
Pet3.delete_all
end
it "it does not depend on mass-assignment" do
lambda do
Pet.new... |
github | seamusabshere/data_miner | https://github.com/seamusabshere/data_miner | test/helper.rb | Ruby | mit | 304 | master | 335 | require 'bundler/setup'
if Bundler.definition.specs['debugger'].first
require 'debugger'
elsif Bundler.definition.specs['ruby-debug'].first
require 'ruby-debug'
end
require 'minitest/spec'
require 'minitest/autorun'
require 'minitest/reporters'
MiniTest::Reporters.use!
require_relative 'support/database'
requir... |
github | seamusabshere/data_miner | https://github.com/seamusabshere/data_miner | test/data_miner/step/test_sql.rb | Ruby | mit | 304 | master | 936 | # -*- encoding: utf-8 -*-
require 'helper'
init_database
class StateBlue < ActiveRecord::Base
self.table_name = 'states'
self.primary_key = 'postal_abbreviation'
data_miner do
sql "Brighter Planet's list of states (as a URL)", 'http://data.brighterplanet.com/states.sql'
end
end
class StateRed < ActiveReco... |
github | seamusabshere/data_miner | https://github.com/seamusabshere/data_miner | test/support/pet2.rb | Ruby | mit | 304 | master | 612 | BREED_BY_LICENSE_NUMBER = File.expand_path('../breed_by_license_number.csv', __FILE__)
class Pet2 < ActiveRecord::Base
self.primary_key = "name"
col :name
col :breed_id
col :license_number, :type => :integer
data_miner do
process :auto_upgrade!
process :run_data_miner_on_parent_associations!
imp... |
github | seamusabshere/data_miner | https://github.com/seamusabshere/data_miner | test/support/pet.rb | Ruby | mit | 304 | master | 1,308 | PETS = File.expand_path('../pets.csv', __FILE__)
PETS_FUNNY = File.expand_path('../pets_funny.csv', __FILE__)
COLOR_DICTIONARY_ENGLISH = File.expand_path('../pet_color_dictionary.en.csv', __FILE__)
COLOR_DICTIONARY_SPANISH = File.expand_path('../pet_color_dictionary.es.csv', __FILE__)
class Pet < ActiveRecord::Base
... |
github | seamusabshere/data_miner | https://github.com/seamusabshere/data_miner | test/support/breed.rb | Ruby | mit | 304 | master | 584 | BREEDS = File.expand_path('../breeds.xls', __FILE__)
class Breed < ActiveRecord::Base
class << self
def update_average_age!
# make sure pet is populated
Pet.run_data_miner!
update_all %{average_age = (SELECT AVG(pets.age) FROM pets WHERE pets.breed_id = breeds.name)}
end
end
self.primar... |
github | seamusabshere/data_miner | https://github.com/seamusabshere/data_miner | test/support/database.rb | Ruby | mit | 304 | master | 1,424 | require 'active_record'
require 'logger'
ActiveRecord::Base.logger = Logger.new $stderr
ActiveRecord::Base.logger.level = (ENV['VERBOSE'] == 'true') ? Logger::DEBUG : Logger::INFO
ActiveRecord::Base.mass_assignment_sanitizer = :strict
require 'active_record_inline_schema'
require 'data_miner'
def init_database
ca... |
github | seamusabshere/data_miner | https://github.com/seamusabshere/data_miner | spec/spec_helper.rb | Ruby | mit | 304 | master | 852 | require 'bundler/setup'
# This file was generated by the `rspec --init` command. Conventionally, all
# specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
# Require this file using `require "spec_helper"` to ensure that it is only
# loaded once.
#
# See http://rubydoc.info/gems/rspec-core/RSpec/... |
github | seamusabshere/data_miner | https://github.com/seamusabshere/data_miner | spec/test_step_spec.rb | Ruby | mit | 304 | master | 3,593 | require 'spec_helper'
class PetTest1 < ActiveRecord::Base
self.primary_key = "name"
col :name
col :favorite_food
data_miner do
process :auto_upgrade!
import("A list of pets", :url => "file://#{Pet::PETS}") do
key :name
store :favorite_food
end
test "Jerry likes cheese" do
expe... |
github | gamache/hyperresource | https://github.com/gamache/hyperresource | Rakefile | Ruby | mit | 304 | master | 811 | require 'rake/testtask'
require './lib/hyper_resource/version'
task :default => [:test]
Rake::TestTask.new do |t|
t.libs << 'test'
t.libs << 'test/lib'
t.test_files = FileList['test/unit/*_test.rb'] +
FileList['test/live/*_test.rb']
t.warning = !!ENV['WARNINGS']
t.verbose = true
end
task :... |
github | gamache/hyperresource | https://github.com/gamache/hyperresource | hyper_resource.gemspec | Ruby | mit | 304 | master | 1,249 | require './lib/hyper_resource/version'
Gem::Specification.new do |s|
s.name = 'hyperresource'
s.version = HyperResource::VERSION
s.date = HyperResource::VERSION_DATE
s.summary = 'Extensible hypermedia client for Ruby'
s.description = <<-EOT
HyperResource is a hypermedia client library for Ruby... |
github | gamache/hyperresource | https://github.com/gamache/hyperresource | test/test_helper.rb | Ruby | mit | 304 | master | 952 | require 'minitest/autorun'
require 'minitest/pride'
require 'mocha/setup'
#require 'debugger'
require 'hyperresource'
HAL_BODY = {
'attr1' => 'val1',
'attr2' => 'val2',
'attr3' => nil,
'_links' => {
'curies' => [
{ 'name' => 'foo',
'templated' => true,
'href' => 'http://example.com/ap... |
github | gamache/hyperresource | https://github.com/gamache/hyperresource | test/unit/config_test.rb | Ruby | mit | 304 | master | 1,870 | require 'test_helper'
describe HyperResource do
describe '#config' do
it 'inherits different masks' do
res1 = HyperResource.new(:root => 'http://example.com')
res1.config('res1' => {'test1' => 123,
'test2' => 123})
link = HyperResource::Link.new(res1, :href => '/')... |
github | gamache/hyperresource | https://github.com/gamache/hyperresource | test/unit/link_test.rb | Ruby | mit | 304 | master | 1,157 | require 'test_helper'
describe HyperResource::Link do
before do
hr = HyperResource.new
@link = HyperResource::Link.new(hr, {'href' => '/foo{?blarg}',
'name' => 'foo',
'templated' => true})
end
describe '#where' do
it '... |
github | gamache/hyperresource | https://github.com/gamache/hyperresource | test/unit/http_test.rb | Ruby | mit | 304 | master | 5,980 | require 'test_helper'
stub_connection = Faraday.new do |builder|
builder.adapter :test do |stub|
stub.get('/') {[ 200, {'Content-type' => 'application/vnd.dummy.v1+hal+json;type=Root'},
<<-EOT
{ "name":"Stub API",
"_links": {
"self": {"href": "/"},
"dummies": {"href": "/dummies{?email,name}", "te... |
github | gamache/hyperresource | https://github.com/gamache/hyperresource | test/unit/embedded_test.rb | Ruby | mit | 304 | master | 2,148 | require 'test_helper'
describe "Embedded Resources" do
class TestAPI < HyperResource; self.root = 'http://example.com' end
it 'supports an array of embedded resources' do
hyper = TestAPI.new
hyper.objects.class.to_s.must_equal 'TestAPI::Objects'
body = { "_embedded" => {
"foo" => [
... |
github | gamache/hyperresource | https://github.com/gamache/hyperresource | test/unit/attributes_test.rb | Ruby | mit | 304 | master | 1,221 | require 'test_helper'
describe HyperResource::Attributes do
class TestAPI < HyperResource; end
describe 'accessors' do
before do
@rsrc = TestAPI.new(:root => 'http://example.com')
@rsrc.adapter.apply(HAL_BODY, @rsrc)
@attrs = @rsrc.attributes
end
it "provides access to all attribute... |
github | gamache/hyperresource | https://github.com/gamache/hyperresource | test/unit/configuration_test.rb | Ruby | mit | 304 | master | 5,179 | require 'test_helper'
describe HyperResource::Configuration do
describe '#get and #set' do
it 'works' do
cfg = HyperResource::Configuration.new
cfg.set('test', 'a', 'b')
cfg.get('test', 'a').must_equal 'b'
cfg.get('test2', 'a').must_be_nil
cfg.get('test', 'b').must_be_nil
end
... |
github | gamache/hyperresource | https://github.com/gamache/hyperresource | test/unit/links_test.rb | Ruby | mit | 304 | master | 1,167 | require 'test_helper'
describe HyperResource::Links do
class TestAPI < HyperResource; end
before do
@rsrc = TestAPI.new
@rsrc.adapter.apply(HAL_BODY, @rsrc)
@links = @rsrc.links
end
describe '#init_from_hal' do
it 'provides readers for all links, including CURIE names' do
assert @links.... |
github | gamache/hyperresource | https://github.com/gamache/hyperresource | test/unit/respond_to_test.rb | Ruby | mit | 304 | master | 847 | require 'test_helper'
describe HyperResource do
class NoMethodsAPI < HyperResource; end
before do
@api = NoMethodsAPI.new(:root => 'http://example.com')
@api.adapter.apply(HAL_BODY, @api)
end
describe 'respond_to' do
it "doesn't create methods" do
@api.methods.wont_include(:attr1)
@ap... |
github | gamache/hyperresource | https://github.com/gamache/hyperresource | test/unit/hyper_resource_test.rb | Ruby | mit | 304 | master | 1,526 | require 'test_helper'
describe HyperResource do
before do
@rsrc = HyperResource.new(:root => 'http://example.com', :href => '/obj1/')
@rsrc.adapter.apply(HAL_BODY, @rsrc)
end
describe 'method_missing' do
it "uses method_missing on :attr methods" do
@rsrc.attr1.must_equal 'val1'
@rsrc.att... |
github | gamache/hyperresource | https://github.com/gamache/hyperresource | test/unit/caching_test.rb | Ruby | mit | 304 | master | 355 | require 'test_helper'
describe 'HyperResource caching' do
class TestAPI < HyperResource; end
before do
@rsrc = TestAPI.new(:root => 'http://example.com')
@rsrc.adapter.apply(HAL_BODY, @rsrc)
end
it 'can be dumped with Marshal.dump' do
dump = Marshal.dump(@rsrc)
new_rsrc = Marshal.load(dump)
... |
github | gamache/hyperresource | https://github.com/gamache/hyperresource | test/unit/filters_test.rb | Ruby | mit | 304 | master | 1,265 | require 'test_helper'
describe 'HyperResource#incoming_body_filter' do
class IncomingBodyFilterAPI < HyperResource
def incoming_body_filter(hash)
super(Hash[ hash.map{|(k,v)| ["awesome_#{k}", "awesomer #{v}"]} ])
end
end
before do
@rsrc = IncomingBodyFilterAPI.new(:root => 'http://example.com'... |
github | gamache/hyperresource | https://github.com/gamache/hyperresource | test/live/two_server_test.rb | Ruby | mit | 304 | master | 3,276 | require 'test_helper'
require 'sinatra'
require 'json'
require File.expand_path('../two_test_servers.rb', __FILE__)
if ENV['NO_LIVE']
puts "Skipping live tests."
exit
elsif RUBY_VERSION[0..2] == '1.8'
puts "Live tests don't run on Ruby 1.8; skipping."
exit
end
launched_servers = false
server_one = nil
serve... |
github | gamache/hyperresource | https://github.com/gamache/hyperresource | test/live/live_test_server.rb | Ruby | mit | 304 | master | 5,696 | #!/usr/bin/env ruby
require 'sinatra'
require 'json'
class LiveTestServer < Sinatra::Base
get '/' do
params = request.env['rack.request.query_hash']
json_params = JSON.dump(params)
headers['Content-type'] = 'application/vnd.example.v1+hal+json;type=Root'
<<-EOT
{ "name": "whatever API",
... |
github | gamache/hyperresource | https://github.com/gamache/hyperresource | test/live/live_test.rb | Ruby | mit | 304 | master | 6,775 | require 'test_helper'
require 'rack'
require 'json'
require File.expand_path('../live_test_server.rb', __FILE__)
if ENV['NO_LIVE']
puts "Skipping live tests."
exit
elsif RUBY_VERSION[0..2] == '1.8'
puts "Live tests don't run on Ruby 1.8; skipping."
exit
end
launched_server = false
server_thread = nil
HR_TEST... |
github | gamache/hyperresource | https://github.com/gamache/hyperresource | test/live/two_test_servers.rb | Ruby | mit | 304 | master | 951 | require 'json'
PORT_ONE = ENV['TEST_PORT_ONE'] || 42774
PORT_TWO = ENV['TEST_PORT_TWO'] || 42775
class ServerOne < Sinatra::Base
get '/' do
params = request.env['rack.request.query_hash']
headers['Content-Type'] = 'application/hal+json'
<<-EOT
{ "name": "Server One",
"sent_params": #{JSON.... |
github | gamache/hyperresource | https://github.com/gamache/hyperresource | lib/hyper_resource.rb | Ruby | mit | 304 | master | 7,614 | require 'hyper_resource/attributes'
require 'hyper_resource/configuration'
require 'hyper_resource/exceptions'
require 'hyper_resource/link'
require 'hyper_resource/links'
require 'hyper_resource/objects'
require 'hyper_resource/version'
require 'hyper_resource/adapter'
require 'hyper_resource/adapter/hal_json'
requi... |
github | gamache/hyperresource | https://github.com/gamache/hyperresource | lib/hyper_resource/objects.rb | Ruby | mit | 304 | master | 994 | class HyperResource
class Objects < Hash
attr_accessor :_resource
def initialize(resource=nil)
self._resource = resource || HyperResource.new
end
# @private
def []=(attr, value)
super(attr.to_s, value)
end
## When +key+ is a string, returns the array of objects under that n... |
github | gamache/hyperresource | https://github.com/gamache/hyperresource | lib/hyper_resource/link.rb | Ruby | mit | 304 | master | 4,244 | require 'uri_template'
require 'hyper_resource/modules/http'
class HyperResource
## HyperResource::Link is an object to represent a hyperlink and its
## URL or body parameters, and to encapsulate HTTP calls involving this
## link. Links are typically created by HyperResource, not by end users.
##
## HTTP m... |
github | gamache/hyperresource | https://github.com/gamache/hyperresource | lib/hyper_resource/attributes.rb | Ruby | mit | 304 | master | 1,907 | class HyperResource
class Attributes < Hash
attr_accessor :_resource # @private
def initialize(resource=nil)
self._resource = resource || HyperResource.new
end
## Returns +true+ if the given attribute has been changed since creation
## time, +false+ otherwise.
## If no attribute is gi... |
github | gamache/hyperresource | https://github.com/gamache/hyperresource | lib/hyper_resource/exceptions.rb | Ruby | mit | 304 | master | 1,056 | class HyperResource
class Exception < ::StandardError
## The internal exception which led to this one, if any.
attr_accessor :cause
# @private
def initialize(message, attrs={})
self.cause = attrs[:cause]
super(message)
end
end
class ResponseError < Exception
## The +Faraday::... |
github | gamache/hyperresource | https://github.com/gamache/hyperresource | lib/hyper_resource/links.rb | Ruby | mit | 304 | master | 1,889 | class HyperResource
## HyperResource::Links is a modified Hash that permits lookup
## of a link by its link relation (rel), or an abbreviation thereof.
## It also provides read access through `method_missing`.
## It is typically created by HyperResource, not by end users.
##
## For example, a link with rel... |
github | gamache/hyperresource | https://github.com/gamache/hyperresource | lib/hyper_resource/configuration.rb | Ruby | mit | 304 | master | 4,763 | require 'uri'
require 'fuzzyurl'
class HyperResource
## HyperResource::Configuration is a class which implements a hostmask-
## scoped set of configurations. Key/value pairs are stored under hostmasks
## like 'api.example.com:8080', 'api.example.com', '*.example.com', or '*'.
## Values are retrieved using a ... |
github | gamache/hyperresource | https://github.com/gamache/hyperresource | lib/hyper_resource/adapter.rb | Ruby | mit | 304 | master | 1,076 | class HyperResource
## HyperResource::Adapter is the interface/abstract base class for
## adapters to different hypermedia formats (e.g., HAL+JSON). New
## adapters must implement the public methods of this class.
class Adapter
class << self
## Serialize the given object into a string.
def ... |
github | gamache/hyperresource | https://github.com/gamache/hyperresource | lib/hyper_resource/modules/config_attributes.rb | Ruby | mit | 304 | master | 8,311 | class HyperResource
module Modules
module ConfigAttributes
ATTRS = [:auth, :headers, :namespace, :adapter, :faraday_options]
def self.included(klass)
klass.extend(ClassMethods)
end
# @private
def hr_config
@hr_config ||= self.class::Configuration.new
end
... |
github | gamache/hyperresource | https://github.com/gamache/hyperresource | lib/hyper_resource/modules/internal_attributes.rb | Ruby | mit | 304 | master | 1,883 | module HyperResource::Modules
module InternalAttributes
def self.included(base)
base.extend(ClassMethods)
base._hr_class_attributes.each do |attr|
base._hr_class_attribute attr
end
(base._hr_attributes - base._hr_class_attributes).each do |attr|
base.send(:attr_accessor... |
github | gamache/hyperresource | https://github.com/gamache/hyperresource | lib/hyper_resource/modules/http.rb | Ruby | mit | 304 | master | 10,870 | require 'faraday'
require 'uri'
require 'json'
require 'digest/md5'
class HyperResource
## Returns this resource's fully qualified URL. Returns nil when
## `root` or `href` are malformed.
def url
begin
URI.join(self.root, (self.href || '')).to_s
rescue StandardError
nil
end
end
##... |
github | gamache/hyperresource | https://github.com/gamache/hyperresource | lib/hyper_resource/modules/data_type.rb | Ruby | mit | 304 | master | 3,369 | class HyperResource
module Modules
module DataType
def self.included(klass)
klass.extend(ClassMethods)
end
# @private
def get_data_type_class(args)
self.class.get_data_type_class(args)
end
# @private
def get_data_type(args)
self.class.get_data_t... |
github | gamache/hyperresource | https://github.com/gamache/hyperresource | lib/hyper_resource/modules/deprecations.rb | Ruby | mit | 304 | master | 1,398 | class HyperResource
module Modules
module Deprecations
def self.included(klass)
klass.extend(ClassMethods)
end
## Show a deprecation message.
# @private
def _hr_deprecate(*args)
self.class._hr_deprecate(*args)
end
module ClassMethods
## Show a d... |
github | gamache/hyperresource | https://github.com/gamache/hyperresource | lib/hyper_resource/adapter/hal_json.rb | Ruby | mit | 304 | master | 2,903 | require 'rubygems' if RUBY_VERSION[0..2] == '1.8'
require 'json'
class HyperResource
class Adapter
## HyperResource::Adapter::HAL_JSON provides support for the HAL+JSON
## hypermedia format by implementing the interface defined in
## HyperResource::Adapter.
class HAL_JSON < Adapter
class << s... |
github | jcrosby/cloudkit | https://github.com/jcrosby/cloudkit | cloudkit.gemspec | Ruby | mit | 304 | master | 1,868 | dir = File.dirname(__FILE__)
require File.expand_path(File.join(dir, 'lib', 'cloudkit', 'version'))
Gem::Specification.new do |s|
s.specification_version = 2 if s.respond_to? :specification_version=
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
s.name ... |
github | jcrosby/cloudkit | https://github.com/jcrosby/cloudkit | Rakefile | Ruby | mit | 304 | master | 755 | require 'rake/clean'
require 'rspec/core'
require 'rspec/core/rake_task'
CLEAN.include 'doc/api'
task :default => :spec
desc "Run all specs in spec directory"
RSpec::Core::RakeTask.new do |task|
task.rspec_opts = ["-c"]
end
desc 'Generate rdoc'
task :rdoc do
rm_rf 'doc/api'
sh((<<-SH).gsub(/[\s\n]+/, ' ').st... |
github | jcrosby/cloudkit | https://github.com/jcrosby/cloudkit | lib/cloudkit.rb | Ruby | mit | 304 | master | 2,259 | require 'openid'
require 'formatador'
require 'json/ext'
require 'erb'
require 'digest/md5'
require 'time'
require 'uuid'
require 'oauth/consumer'
require 'oauth/request_proxy/rack_request'
require 'oauth/server'
require 'oauth/signature'
require 'cloudkit/generator'
require 'cloudkit/command'
require 'cloudkit/constan... |
github | jcrosby/cloudkit | https://github.com/jcrosby/cloudkit | lib/cloudkit/user_store.rb | Ruby | mit | 304 | master | 907 | module CloudKit
# A thin layer on top of CloudKit::Store providing consistent URIs and
# automatic upgrades if required for future releases.
class UserStore
@@store = nil
def initialize(uri=nil)
unless @@store
@@store = Store.new(:collections => [:cloudkit_users])
end
end
de... |
github | jcrosby/cloudkit | https://github.com/jcrosby/cloudkit | lib/cloudkit/store.rb | Ruby | mit | 304 | master | 16,234 | require 'tmpdir'
module CloudKit
# A functional storage interface with HTTP semantics and pluggable adapters.
class Store
include ResponseHelpers
include CloudKit::Util
# Locks operations around the URI so that the store returns consistent data
#
# FIXME: Move this into the storage adaptor so... |
github | jcrosby/cloudkit | https://github.com/jcrosby/cloudkit | lib/cloudkit/generator.rb | Ruby | mit | 304 | master | 1,150 | module CloudKit
module Generator
def copy_contents(template_root, destination_root)
paths(template_root).each do |template_path|
if File.directory?(template_path)
generate_directory(template_path, destination_root)
copy_contents(template_path, File.join(destination_root, File.bas... |
github | jcrosby/cloudkit | https://github.com/jcrosby/cloudkit | lib/cloudkit/uri.rb | Ruby | mit | 304 | master | 2,932 | require 'uri'
module CloudKit
# A CloudKit::URI wraps a URI string, adding methods useful for routing
# in CloudKit as well as caching URI components for future comparisons.
class URI
# The string form of a URI.
attr_reader :string
# Create a new URI with the given string.
def initialize(string... |
github | jcrosby/cloudkit | https://github.com/jcrosby/cloudkit | lib/cloudkit/command.rb | Ruby | mit | 304 | master | 1,051 | module CloudKit
class Command
include CloudKit::Generator
def run(args)
return help unless command = args.first
case command
when 'run'
run_app
when 'help'
help
else
@app_name = destination_root = command
template_root = File.join(File.expand_path... |
github | jcrosby/cloudkit | https://github.com/jcrosby/cloudkit | lib/cloudkit/exceptions.rb | Ruby | mit | 304 | master | 397 | module CloudKit
# HistoricalIntegrityViolation exceptions are raised when an attempt is made
# to modify an archived or deleted version of a resource.
class HistoricalIntegrityViolation < Exception; end
# InvalidURIFormat exceptions are raised during attempts to get or generate
# cannonical URIs from non-co... |
github | jcrosby/cloudkit | https://github.com/jcrosby/cloudkit | lib/cloudkit/constants.rb | Ruby | mit | 304 | master | 1,160 | module CloudKit
module Constants
# The key used to store the authenticated user.
CLOUDKIT_AUTH_KEY = 'cloudkit.user'.freeze
# The key used to indicate the presence of auth in a stack.
CLOUDKIT_AUTH_PRESENCE = 'cloudkit.auth'.freeze
# The key used to store auth challenge headers shared between
... |
github | jcrosby/cloudkit | https://github.com/jcrosby/cloudkit | lib/cloudkit/openid_store.rb | Ruby | mit | 304 | master | 3,376 | require 'openid/store/interface'
module CloudKit
# An OpenIDStore provides the interface expected by the ruby-openid gem,
# mapping it to a CloudKit::Store instance.
class OpenIDStore < OpenID::Store::Interface
@@store = nil
# Initialize an OpenIDStore.
def initialize
unless @@store
@@... |
github | jcrosby/cloudkit | https://github.com/jcrosby/cloudkit | lib/cloudkit/oauth_filter.rb | Ruby | mit | 304 | master | 9,509 | module CloudKit
# An OAuthFilter provides both OAuth 1.0 support, plus OAuth Discovery.
#
# Responds to the following URIs as part of the OAuth 1.0 "dance":
#
# /oauth/request_tokens
# /oauth/authorization
# /oauth/authorized_request_tokens/{id}
# /oauth/access_tokens
#
# Responds to the ... |
github | jcrosby/cloudkit | https://github.com/jcrosby/cloudkit | lib/cloudkit/openid_filter.rb | Ruby | mit | 304 | master | 7,343 | module CloudKit
# An OpenIDFilter provides OpenID authentication, listening for upstream
# OAuth authentication and bypassing if already authorized.
#
# The root URI, "/", is always bypassed. More URIs can also be bypassed using
# the :allow option:
#
# use Rack::Session::Pool
# use OpenIDFilter, :... |
github | jcrosby/cloudkit | https://github.com/jcrosby/cloudkit | lib/cloudkit/oauth_store.rb | Ruby | mit | 304 | master | 1,423 | module CloudKit
# An OAuthStore is a thin abstraction around CloudKit::Store, providing
# consistent collection names, and allowing automatic upgrades in later
# releases if needed.
class OAuthStore
@@store = nil
# Initialize a Store for use with OAuth middleware. Load the static consumer
# resour... |
github | jcrosby/cloudkit | https://github.com/jcrosby/cloudkit | lib/cloudkit/service.rb | Ruby | mit | 304 | master | 5,112 | module CloudKit
# A CloudKit Service is Rack middleware providing a REST/HTTP 1.1 interface to
# a Store. Its primary purpose is to initialize and adapt a Store for use in a
# Rack middleware stack.
#
# ==Examples
#
# A rackup file exposing _items_ and _things_ as REST collections:
# require 'cloudki... |
github | jcrosby/cloudkit | https://github.com/jcrosby/cloudkit | lib/cloudkit/request.rb | Ruby | mit | 304 | master | 5,491 | module CloudKit
# A subclass of Rack::Request providing CloudKit-specific features.
class Request < Rack::Request
include CloudKit::Util
alias_method :cloudkit_params, :params
def initialize(env)
super(env)
end
# Return a merged set of both standard params and OAuth header params.
d... |
github | jcrosby/cloudkit | https://github.com/jcrosby/cloudkit | lib/cloudkit/flash_session.rb | Ruby | mit | 304 | master | 380 | module CloudKit
# FlashSessions are hashes that forget their contents after the first access.
# Useful for session-based messaging.
class FlashSession
def initialize
@values = {}
end
# Set the value for a key.
def []=(k, v)
@values[k] = v
end
# Access a value, then forget ... |
github | jcrosby/cloudkit | https://github.com/jcrosby/cloudkit | lib/cloudkit/util.rb | Ruby | mit | 304 | master | 686 | module CloudKit
module Util
# Render ERB content
def erb(request, template, headers={'Content-Type' => 'text/html'}, status=200)
template_file = open(
File.join(File.dirname(__FILE__),
'templates',
"#{template.to_s}.erb"))
template = ERB.new(template_file.read)
resul... |
github | jcrosby/cloudkit | https://github.com/jcrosby/cloudkit | lib/cloudkit/rack/builder.rb | Ruby | mit | 304 | master | 3,132 | module Rack #:nodoc:
class Builder
alias_method :cloudkit_to_app, :to_app
# Extends Rack::Builder's to_app method to detect if the last piece of
# middleware in the stack is a CloudKit shortcut (contain or expose), adding
# a default developer page at the root and a 404 everywhere else.
def to_ap... |
github | jcrosby/cloudkit | https://github.com/jcrosby/cloudkit | lib/cloudkit/rack/router.rb | Ruby | mit | 304 | master | 566 | module Rack #:nodoc:
# A minimal router providing just what is needed for the OAuth and OpenID
# filters.
class Router
# Create an instance of Router to match on method, path and params.
def initialize(method, path, params=[])
@method = method.to_s.upcase; @path = path; @params = params
end
... |
github | jcrosby/cloudkit | https://github.com/jcrosby/cloudkit | lib/cloudkit/store/response_helpers.rb | Ruby | mit | 304 | master | 2,227 | # A set of mixins for building CloudKit::Response objects.
module CloudKit::ResponseHelpers
def status_404
json_error_response(404, 'not found')
end
def status_405(methods)
response = json_error_response(405, 'method not allowed')
response['Allow'] = methods.join(', ')
response
end
def statu... |
github | jcrosby/cloudkit | https://github.com/jcrosby/cloudkit | lib/cloudkit/store/resource.rb | Ruby | mit | 304 | master | 8,449 | module CloudKit
# A CloudKit::Resource represents a "resource" in the REST/HTTP sense of the
# word. It encapsulates a JSON document and its metadata such as its URI, ETag,
# Last-Modified date, remote user, and historical versions.
class Resource
attr_reader :uri, :etag, :last_modified, :json, :remote_us... |
github | jcrosby/cloudkit | https://github.com/jcrosby/cloudkit | lib/cloudkit/store/response.rb | Ruby | mit | 304 | master | 1,207 | module CloudKit
# A response wrapper for CloudKit::Store
class Response
include Util
attr_reader :status, :meta, :content
# Create an instance of a Response.
def initialize(status, meta, content='')
@status = status; @meta = meta; @content = content
end
# Return the header value sp... |
github | jcrosby/cloudkit | https://github.com/jcrosby/cloudkit | lib/cloudkit/store/memory_table.rb | Ruby | mit | 304 | master | 4,420 | module CloudKit
# A MemoryTable implements the essential pieces of the Rufus Tokyo Table API
# required for CloudKit's operation. It is basically a hash of hashes with
# querying capabilities. None of the data is persisted to disk nor is it
# designed with production use in mind. The primary purpose is to enab... |
github | jcrosby/cloudkit | https://github.com/jcrosby/cloudkit | lib/cloudkit/store/mongo_store.rb | Ruby | mit | 304 | master | 16,524 | require 'mongo'
require 'bson'
module CloudKit
class MongoStore
attr_reader :db, :safe_write_options
# Creates a MongoStore, setting up the db and internal meta_collection if necessary
#
# Any options not listed below are passed as options to Mongo::Connection.multi
#
# @param [Hash] option... |
github | jcrosby/cloudkit | https://github.com/jcrosby/cloudkit | lib/cloudkit/templates/gen/config.ru | Ruby | mit | 304 | master | 355 | begin
require File.expand_path('.bundle/environment', __FILE__)
rescue LoadError
require 'rubygems'
require 'bundler'
Bundler.setup
end
Bundler.require
require File.expand_path(File.join(File.dirname(__FILE__), 'lib', '<%= @app_name %>'))
use Rack::Static, :urls => ["/css", "/img", "/js"], :root => "public"
r... |
github | jcrosby/cloudkit | https://github.com/jcrosby/cloudkit | spec/ext_spec.rb | Ruby | mit | 304 | master | 1,629 | require 'spec_helper'
describe "A Hash" do
it "should re-key an entry if it exists" do
x = {:a => 1, :b => 2}
x.rekey!(:b, :c)
x.should == {:a => 1, :c => 2}
x.rekey!(:d, :b)
x.should == {:a => 1, :c => 2}
end
it "should re-key false and nil values" do
x = {:a => false, :b => nil}
x... |
github | jcrosby/cloudkit | https://github.com/jcrosby/cloudkit | spec/service_spec.rb | Ruby | mit | 304 | master | 35,314 | require 'spec_helper'
describe "A CloudKit::Service" do
it "should return a 501 for unimplemented methods" do
app = Rack::Builder.new {
use Rack::Lint
use CloudKit::Service, :collections => [:items, :things]
run echo_text('martino')
}
response = Rack::MockRequest.new(app).request('TRA... |
github | jcrosby/cloudkit | https://github.com/jcrosby/cloudkit | spec/oauth_filter_spec.rb | Ruby | mit | 304 | master | 13,064 | require 'spec_helper'
describe "An OAuthFilter" do
before(:each) do
CloudKit.setup_storage_adapter unless CloudKit.storage_adapter
@oauth_filtered_app = CloudKit::OAuthFilter.new(echo_env(CLOUDKIT_AUTH_KEY))
token = JSON.generate(
:secret => 'pfkkdhi9sl3r4s00',
:consumer_key => '... |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.