conduit 0.3.0 → 0.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (89) hide show
  1. checksums.yaml +4 -4
  2. data/Rakefile +1 -21
  3. data/lib/conduit.rb +4 -6
  4. data/lib/conduit/configuration.rb +20 -31
  5. data/lib/conduit/core/action.rb +15 -2
  6. data/lib/conduit/core/connection.rb +3 -1
  7. data/lib/conduit/core/parser.rb +7 -3
  8. data/lib/conduit/storage.rb +2 -2
  9. data/lib/conduit/version.rb +1 -1
  10. data/lib/tmp/conduit/1/fusion/activate/request.xml +26 -0
  11. data/lib/tmp/conduit/1/fusion/change_device/request.xml +15 -0
  12. data/lib/tmp/conduit/1/fusion/change_number/request.xml +14 -0
  13. data/lib/tmp/conduit/1/fusion/deactivate/request.xml +14 -0
  14. data/lib/tmp/conduit/1/fusion/purchase/1-response.xml +1 -0
  15. data/lib/tmp/conduit/1/fusion/purchase/request.xml +15 -0
  16. data/lib/tmp/conduit/1/fusion/query_subscription/1-response.xml +1 -0
  17. data/lib/tmp/conduit/1/fusion/query_subscription/request.xml +15 -0
  18. data/lib/tmp/conduit/1/fusion/reset_voicemail/request.xml +14 -0
  19. data/lib/tmp/conduit/1/fusion/restore/request.xml +14 -0
  20. data/lib/tmp/conduit/1/fusion/suspend/request.xml +15 -0
  21. data/lib/tmp/conduit/2/fusion/purchase/request.xml +15 -0
  22. data/lib/tmp/conduit/3/fusion/activate/request.xml +26 -0
  23. data/lib/tmp/conduit/4/fusion/activate/request.xml +26 -0
  24. data/lib/tmp/conduit/5/fusion/activate/request.xml +26 -0
  25. data/lib/tmp/conduit/6/fusion/activate/request.xml +26 -0
  26. data/lib/tmp/conduit/7/fusion/activate/request.xml +26 -0
  27. data/lib/tmp/conduit/8/fusion/activate/request.xml +26 -0
  28. data/lib/tmp/conduit/9/fusion/activate/request.xml +26 -0
  29. data/spec/classes/core/action_spec.rb +11 -2
  30. data/spec/classes/core/parser_spec.rb +52 -0
  31. data/spec/spec_helper.rb +13 -17
  32. data/spec/{dummy/lib/conduit/drivers → support}/my_driver/actions/foo.rb +0 -0
  33. data/spec/{dummy/lib/conduit/drivers → support}/my_driver/driver.rb +0 -0
  34. data/spec/support/my_driver/parsers/foo.rb +75 -0
  35. data/spec/{dummy/lib/conduit/drivers → support}/my_driver/views/foo.erb +0 -0
  36. data/spec/{dummy/lib/conduit/drivers → support}/my_driver/views/layout.erb +0 -0
  37. data/spec/support/xml/xml_response.xml +3 -0
  38. metadata +45 -140
  39. data/app/controllers/conduit/responses_controller.rb +0 -14
  40. data/app/models/conduit/concerns/storage.rb +0 -41
  41. data/app/models/conduit/request.rb +0 -111
  42. data/app/models/conduit/response.rb +0 -50
  43. data/app/models/conduit/subscription.rb +0 -6
  44. data/config/routes.rb +0 -3
  45. data/db/migrate/20131209223122_create_conduit_requests.rb +0 -13
  46. data/db/migrate/20131209223734_create_conduit_responses.rb +0 -10
  47. data/db/migrate/20140305202729_create_conduit_subscriptions.rb +0 -12
  48. data/lib/conduit/acts_as_conduit_subscriber.rb +0 -41
  49. data/lib/conduit/engine.rb +0 -20
  50. data/lib/tasks/conduit_tasks.rake +0 -4
  51. data/spec/classes/acts_as_conduit_subscriber_spec.rb +0 -61
  52. data/spec/controllers/responses_controller_spec.rb +0 -29
  53. data/spec/dummy/README.rdoc +0 -28
  54. data/spec/dummy/Rakefile +0 -6
  55. data/spec/dummy/app/assets/javascripts/application.js +0 -13
  56. data/spec/dummy/app/assets/stylesheets/application.css +0 -13
  57. data/spec/dummy/app/controllers/application_controller.rb +0 -5
  58. data/spec/dummy/app/helpers/application_helper.rb +0 -2
  59. data/spec/dummy/app/views/layouts/application.html.erb +0 -14
  60. data/spec/dummy/bin/bundle +0 -3
  61. data/spec/dummy/bin/rails +0 -4
  62. data/spec/dummy/bin/rake +0 -4
  63. data/spec/dummy/config.ru +0 -4
  64. data/spec/dummy/config/application.rb +0 -29
  65. data/spec/dummy/config/boot.rb +0 -5
  66. data/spec/dummy/config/database.yml +0 -12
  67. data/spec/dummy/config/environment.rb +0 -5
  68. data/spec/dummy/config/environments/development.rb +0 -29
  69. data/spec/dummy/config/environments/production.rb +0 -80
  70. data/spec/dummy/config/environments/test.rb +0 -36
  71. data/spec/dummy/config/initializers/backtrace_silencers.rb +0 -7
  72. data/spec/dummy/config/initializers/conduit.rb +0 -5
  73. data/spec/dummy/config/initializers/filter_parameter_logging.rb +0 -4
  74. data/spec/dummy/config/initializers/inflections.rb +0 -16
  75. data/spec/dummy/config/initializers/mime_types.rb +0 -5
  76. data/spec/dummy/config/initializers/secret_token.rb +0 -12
  77. data/spec/dummy/config/initializers/session_store.rb +0 -3
  78. data/spec/dummy/config/initializers/wrap_parameters.rb +0 -14
  79. data/spec/dummy/config/locales/en.yml +0 -23
  80. data/spec/dummy/config/routes.rb +0 -3
  81. data/spec/dummy/db/test.sqlite3 +0 -0
  82. data/spec/dummy/db/test.sqlite3-journal +0 -0
  83. data/spec/dummy/lib/conduit/drivers/my_driver/parsers/foo.rb +0 -13
  84. data/spec/dummy/log/test.log +0 -6
  85. data/spec/dummy/public/404.html +0 -58
  86. data/spec/dummy/public/422.html +0 -58
  87. data/spec/dummy/public/500.html +0 -57
  88. data/spec/models/conduit/request_spec.rb +0 -50
  89. data/spec/models/conduit/response_spec.rb +0 -52
@@ -1,14 +0,0 @@
1
- module Conduit
2
- class ResponsesController < ActionController::Base
3
-
4
- # TODO: Determine the actual param the posted content
5
- # will be stored in, and modify the code below
6
- #
7
- def create
8
- request = Conduit::Request.find(params[:request_id])
9
- request.responses.create(content: params[:content])
10
- render nothing: true
11
- end
12
-
13
- end
14
- end
@@ -1,41 +0,0 @@
1
- module Conduit
2
- module Concerns
3
- module Storage
4
- extend ActiveSupport::Concern
5
-
6
- included do
7
- attr_writer :content
8
-
9
- after_create :add_to_storage, if: :generate_storage_path
10
- after_destroy :remove_from_storage, if: :file
11
- end
12
-
13
- # Read the content from the storage location
14
- #
15
- def content
16
- @content ||= Conduit::Storage.read(file)
17
- end
18
-
19
- private
20
-
21
- # Generate a unique storage key
22
- #
23
- def generate_storage_path
24
- false
25
- end
26
-
27
- # Remove the file from remote storage
28
- #
29
- def remove_from_storage
30
- Conduit::Storage.delete(file)
31
- end
32
-
33
- # Write the content to the storage location
34
- #
35
- def add_to_storage
36
- Conduit::Storage.write(file, content)
37
- end
38
-
39
- end
40
- end
41
- end
@@ -1,111 +0,0 @@
1
- module Conduit
2
- class Request < ActiveRecord::Base
3
- include Conduit::Concerns::Storage
4
-
5
- serialize :options, Hash
6
-
7
- # Associations
8
-
9
- has_many :responses, dependent: :destroy
10
- has_many :subscriptions, autosave: true
11
-
12
- # Validations
13
-
14
- validates :driver, presence: true
15
- validates :action, presence: true
16
-
17
- # Hooks
18
-
19
- after_initialize :set_defaults
20
- after_update :notify_subscribers
21
-
22
- # Scopes
23
-
24
- scope :by_action, -> (actions) { where(action: actions) }
25
- scope :by_driver, -> (drivers) { where(driver: drivers) }
26
- scope :by_status, -> (status) { where(status: status) }
27
-
28
- # Methods
29
-
30
- # Overriding this method fixes an issue
31
- # where content isn't set until after
32
- # the raw action is instantiated
33
- #
34
- def content
35
- raw.view || super
36
- end
37
-
38
- # Perform the requested action for the specified driver
39
- # We need to also capture any timeouts, and update
40
- # the status accordingly.
41
- #
42
- def perform_request
43
- return unless response = raw.perform
44
- responses.create(content: response.body)
45
- rescue Excon::Errors::Timeout
46
- update_attributes(status: :timeout)
47
- end
48
-
49
- # Allow creation of subscriptions through the
50
- # subscribers virtual attribute.
51
- #
52
- # NOTE: This is usually possible by default with a
53
- # has_many :through, but with polymorphic
54
- # association it gets more complicated.
55
- #
56
- def subscribers=(args)
57
- args.map do |arg|
58
- next unless arg.class < ActiveRecord::Base
59
- subscriptions.build(subscriber: arg)
60
- end
61
- end
62
-
63
- # Fetch a list of subscribers through
64
- # the subscriptions association
65
- #
66
- # NOTE: This is usually possible by default with a
67
- # has_many :through, but with polymorphic
68
- # association it gets more complicated.
69
- #
70
- def subscribers
71
- subscriptions.map(&:subscriber)
72
- end
73
-
74
- private
75
-
76
- # Set some default values
77
- #
78
- def set_defaults
79
- self.status ||= "open"
80
- end
81
-
82
- # Generate a unique storage key
83
- # TODO: Dynamic File Format
84
- #
85
- def generate_storage_path
86
- update_column(:file, File.join("#{id}".reverse!,
87
- driver.to_s, action.to_s, "request.xml"))
88
- end
89
-
90
- # Notify the requestable that our status
91
- # has changed. This is done by calling
92
- # a predefined method name on the
93
- # requestable instance
94
- #
95
- def notify_subscribers
96
- last_response = responses.last
97
- subscribers.each do |subscriber|
98
- subscriber.after_conduit_update(action,
99
- last_response.parsed_content)
100
- end
101
- end
102
-
103
- # Raw access to the action instance
104
- #
105
- def raw
106
- @raw ||= Conduit::Util.find_driver(driver,
107
- action).new(options.symbolize_keys!)
108
- end
109
-
110
- end
111
- end
@@ -1,50 +0,0 @@
1
- module Conduit
2
- class Response < ActiveRecord::Base
3
- include Conduit::Concerns::Storage
4
-
5
- # Associations
6
-
7
- belongs_to :request
8
-
9
- # Validations
10
-
11
- validates :request, presence: true
12
-
13
- # Hooks
14
-
15
- after_create :report_response_status
16
-
17
- # Methods
18
-
19
- delegate :driver, :action, to: :request
20
-
21
- # Raw access to the parser instance
22
- #
23
- def parsed_content
24
- @parsed_content ||= Conduit::Util.find_driver(driver, action, 'parser').new(content)
25
- end
26
-
27
- private
28
-
29
- # Generate a storage key based on parent request
30
- # TODO: Dynamic File Format
31
- #
32
- def generate_storage_path
33
- update_column(:file, File.join(File.dirname(
34
- request.file), "#{id}-response.xml"))
35
- end
36
-
37
- # Check for the 'response_status' attribute
38
- # from the parsed data, and return that to
39
- # the request.
40
- #
41
- # NOTE: These should be one of the following:
42
- # pending/success/failure
43
- #
44
- def report_response_status
45
- status = parsed_content.response_status
46
- request.update_attributes(status: status)
47
- end
48
-
49
- end
50
- end
@@ -1,6 +0,0 @@
1
- module Conduit
2
- class Subscription < ActiveRecord::Base
3
- belongs_to :subscriber, polymorphic: true
4
- belongs_to :request, class_name: 'Conduit::Request'
5
- end
6
- end
@@ -1,3 +0,0 @@
1
- Conduit::Engine.routes.draw do
2
- resources :responses, only: [:create]
3
- end
@@ -1,13 +0,0 @@
1
- class CreateConduitRequests < ActiveRecord::Migration
2
- def change
3
- create_table :conduit_requests do |t|
4
- t.string :driver
5
- t.string :action
6
- t.text :options
7
- t.string :file
8
- t.string :status
9
-
10
- t.timestamps
11
- end
12
- end
13
- end
@@ -1,10 +0,0 @@
1
- class CreateConduitResponses < ActiveRecord::Migration
2
- def change
3
- create_table :conduit_responses do |t|
4
- t.string :file
5
- t.references :request, index: true
6
-
7
- t.timestamps
8
- end
9
- end
10
- end
@@ -1,12 +0,0 @@
1
- class CreateConduitSubscriptions < ActiveRecord::Migration
2
- def change
3
- create_table :conduit_subscriptions do |t|
4
- t.references :request, index: true
5
- t.integer :subscriber_id
6
- t.string :subscriber_type
7
-
8
- t.timestamps
9
- end
10
- add_index :conduit_subscriptions, [:subscriber_type, :subscriber_id], name: 'index_conduit_subscriptions_on_subscriber'
11
- end
12
- end
@@ -1,41 +0,0 @@
1
- module Conduit
2
- module ActsAsConduitSubscriber
3
- extend ActiveSupport::Concern
4
-
5
- module ClassMethods
6
-
7
- # Define a method that can be used to inject
8
- # methods into an ActiveRecord Model
9
- #
10
- def acts_as_conduit_subscriber
11
- include Conduit::ActsAsConduitSubscriber::LocalInstanceMethods
12
-
13
- has_many :conduit_subscriptions, as: :subscriber, class_name: 'Conduit::Subscription'
14
- has_many :conduit_requests, through: :conduit_subscriptions, source: :request
15
- end
16
-
17
- end
18
-
19
- # These methods are included when acts_as_conduit_request
20
- # is called on an ActiveRecord Model
21
- #
22
- module LocalInstanceMethods
23
-
24
- # Fire this method after the last conduit
25
- # request has been updated
26
- #
27
- # NOTE: This could probably be better
28
- # handled by observers, or a
29
- # custom callback.
30
- #
31
- def after_conduit_update(action, parsed_response)
32
- # This method should be overriden
33
- # on the requestable object
34
- end
35
-
36
- end
37
-
38
- end
39
- end
40
-
41
- ActiveRecord::Base.send :include, Conduit::ActsAsConduitSubscriber
@@ -1,20 +0,0 @@
1
- module Conduit
2
- class Engine < ::Rails::Engine
3
- isolate_namespace Conduit
4
-
5
- config.generators do |g|
6
- g.test_framework :rspec, :fixture => false
7
- g.assets false
8
- g.helper false
9
- end
10
-
11
- initializer "conduit.load_app_root", before: :load_config_initializers do |app|
12
- Conduit.app_root = app.root
13
- end
14
-
15
- initializer 'conduit.load_drivers', after: :load_config_initializers do |app|
16
- Conduit::Driver.load_drivers
17
- end
18
-
19
- end
20
- end
@@ -1,4 +0,0 @@
1
- # desc "Explaining what the task does"
2
- # task :conduit do
3
- # # Task goes here
4
- # end
@@ -1,61 +0,0 @@
1
- require 'spec_helper'
2
-
3
- # Create a temporary ActiveRecord object to test with
4
- #
5
- class MySubscriber < ActiveRecord::Base
6
- acts_as_conduit_subscriber
7
-
8
- # Update the `updated_at` timestamp
9
- # so we know this has been called
10
- #
11
- def after_conduit_update(action, parsed_response)
12
- self.update_column(:updated_at, 1.day.from_now)
13
- end
14
- end
15
-
16
- describe MySubscriber do
17
-
18
- # Silly magic to create an empty table for MySubscriber
19
- #
20
- before(:all) do
21
- ActiveRecord::Migration.tap do |a|
22
- a.verbose = false
23
- a.create_table(:my_subscribers) do |t|
24
- t.timestamps
25
- end
26
- end
27
- end
28
-
29
- # Silly magic to remove an empty table for MySubscriber
30
- #
31
- after(:all) do
32
- ActiveRecord::Migration.tap do |a|
33
- a.verbose = false
34
- a.drop_table(:my_subscribers)
35
- end
36
- end
37
-
38
- context 'without an instance' do
39
- its(:class) { should respond_to(:acts_as_conduit_subscriber) }
40
- it { should have_many :conduit_requests }
41
- end
42
-
43
- context 'with an instance' do
44
- before(:each) do
45
- Excon.stub({}, body: read_support_file("xml/xml_response.xml"), status: 200)
46
-
47
- @obj = MySubscriber.create
48
- @obj.conduit_requests.create(driver: :my_driver, action: :foo,
49
- options: request_attributes).perform_request
50
- end
51
-
52
- describe '#after_conduit_update' do
53
- it 'gets called after a request is updated' do
54
- @obj.reload # Bust the cache
55
- @obj.updated_at.should_not == @obj.created_at
56
- end
57
- end
58
-
59
- end
60
-
61
- end
@@ -1,29 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe Conduit::ResponsesController do
4
-
5
- let(:request) do
6
- Conduit::Request.create(driver: :my_driver,
7
- action: :foo, options: request_attributes)
8
- end
9
-
10
- let(:xml_content) do
11
- read_support_file('xml/xml_response.xml')
12
- end
13
-
14
- describe 'create' do
15
- before do
16
- post :create, { request_id: request.id,
17
- content: xml_content, use_route: :conduit }
18
- end
19
-
20
- it 'returns a 200 status' do
21
- response.status.should == 200
22
- end
23
-
24
- it 'creates a response object' do
25
- request.responses.length.should == 1
26
- end
27
- end
28
-
29
- end
@@ -1,28 +0,0 @@
1
- == README
2
-
3
- This README would normally document whatever steps are necessary to get the
4
- application up and running.
5
-
6
- Things you may want to cover:
7
-
8
- * Ruby version
9
-
10
- * System dependencies
11
-
12
- * Configuration
13
-
14
- * Database creation
15
-
16
- * Database initialization
17
-
18
- * How to run the test suite
19
-
20
- * Services (job queues, cache servers, search engines, etc.)
21
-
22
- * Deployment instructions
23
-
24
- * ...
25
-
26
-
27
- Please feel free to use a different markup language if you do not plan to run
28
- <tt>rake doc:app</tt>.