Class: Frank::Cucumber::Gateway
- Inherits:
-
Object
- Object
- Frank::Cucumber::Gateway
- Defined in:
- lib/frank-cucumber/gateway.rb
Constant Summary collapse
- DEFAULT_BASE_URL =
"http://localhost:37265/"
Class Method Summary collapse
- .build_operation_map(method_sig, method_args) ⇒ Object
- .evaluate_frankly_response(json, req_desc) ⇒ Object
Instance Method Summary collapse
-
#initialize(base_url = nil) ⇒ Gateway
constructor
A new instance of Gateway.
- #ping ⇒ Object
- #send_get(verb) ⇒ Object
-
#send_post(verb, command) ⇒ Object
taken from Ian Dee’s Encumber.
Constructor Details
#initialize(base_url = nil) ⇒ Gateway
Returns a new instance of Gateway.
9 10 11 |
# File 'lib/frank-cucumber/gateway.rb', line 9 def initialize( base_url = nil ) @base_url = URI.parse( (base_url || DEFAULT_BASE_URL).to_s ) end |
Class Method Details
.build_operation_map(method_sig, method_args) ⇒ Object
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/frank-cucumber/gateway.rb', line 21 def build_operation_map( method_sig, method_args ) num_args_according_to_method_sig = method_sig.count(':') if num_args_according_to_method_sig != method_args.count raise <<-EOS The method you've specified - #{method_sig} - wants #{num_args_according_to_method_sig} arguments, but you've supplied #{method_args.count} arguments. EOS end if num_args_according_to_method_sig > 0 && !method_sig.end_with?(':') raise <<-EOS The method signature you've specified - #{method_sig} - is invalid. Objective C method signatures which take parameters must end with a : EOS end { :method_name => method_sig, :arguments => method_args, } end |
.evaluate_frankly_response(json, req_desc) ⇒ Object
46 47 48 49 50 51 52 53 |
# File 'lib/frank-cucumber/gateway.rb', line 46 def evaluate_frankly_response( json, req_desc ) res = JSON.parse( json ) if res['outcome'] != 'SUCCESS' raise "#{req_desc} failed because: #{res['reason']}\n#{res['details']}" end res['results'] end |
Instance Method Details
#ping ⇒ Object
13 14 15 16 17 18 |
# File 'lib/frank-cucumber/gateway.rb', line 13 def ping send_get('') return true rescue FrankNetworkError return false end |
#send_get(verb) ⇒ Object
67 68 69 70 71 |
# File 'lib/frank-cucumber/gateway.rb', line 67 def send_get( verb ) url = frank_url_for( verb ) req = Net::HTTP::Get.new url.path make_http_request( url, req ) end |
#send_post(verb, command) ⇒ Object
taken from Ian Dee’s Encumber
57 58 59 60 61 62 63 64 65 |
# File 'lib/frank-cucumber/gateway.rb', line 57 def send_post( verb, command ) command = command.to_json unless command.is_a? String url = frank_url_for( verb ) req = Net::HTTP::Post.new url.path req.body = command make_http_request( url, req ) end |