Class: HaveAPI::Client::Action
- Inherits:
-
Object
- Object
- HaveAPI::Client::Action
- Defined in:
- lib/haveapi/client/action.rb
Instance Attribute Summary collapse
-
#resource_path ⇒ Object
Returns the value of attribute resource_path.
Instance Method Summary collapse
- #aliases(include_name = false) ⇒ Object
- #auth? ⇒ Boolean
- #description ⇒ Object
- #examples ⇒ Object
- #execute(data, *_) ⇒ Object
- #help ⇒ Object
- #http_method ⇒ Object
-
#initialize(api, name, spec, args) ⇒ Action
constructor
A new instance of Action.
- #input ⇒ Object
- #input_layout ⇒ Object
- #input_params ⇒ Object
- #name ⇒ Object
- #namespace(src) ⇒ Object
- #output ⇒ Object
- #output_layout ⇒ Object
- #param_description(dir, name) ⇒ Object
- #params ⇒ Object
- #prepared_help ⇒ Object
-
#prepared_url ⇒ Object
Url with resolved parameters.
- #provide_args(*args) ⇒ Object
- #provide_url(url, help) ⇒ Object
- #structure ⇒ Object
- #unresolved_args? ⇒ Boolean
- #update_description(spec) ⇒ Object
- #url ⇒ Object
Constructor Details
#initialize(api, name, spec, args) ⇒ Action
Returns a new instance of Action.
5 6 7 8 9 10 11 |
# File 'lib/haveapi/client/action.rb', line 5 def initialize(api, name, spec, args) @api = api @name = name @spec = spec apply_args(args) end |
Instance Attribute Details
#resource_path ⇒ Object
Returns the value of attribute resource_path.
3 4 5 |
# File 'lib/haveapi/client/action.rb', line 3 def resource_path @resource_path end |
Instance Method Details
#aliases(include_name = false) ⇒ Object
34 35 36 37 38 39 40 |
# File 'lib/haveapi/client/action.rb', line 34 def aliases(include_name = false) if include_name [@name] + @spec[:aliases] else @spec[:aliases] end end |
#auth? ⇒ Boolean
30 31 32 |
# File 'lib/haveapi/client/action.rb', line 30 def auth? @spec[:auth] end |
#description ⇒ Object
42 43 44 |
# File 'lib/haveapi/client/action.rb', line 42 def description @spec[:description] end |
#examples ⇒ Object
70 71 72 |
# File 'lib/haveapi/client/action.rb', line 70 def examples @spec[:examples] end |
#execute(data, *_) ⇒ Object
13 14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/haveapi/client/action.rb', line 13 def execute(data, *_) params = Params.new(self, data) unless params.valid? raise ValidationError.new(self, params.errors) end ret = @api.call(self, params.to_api) @prepared_url = nil @prepared_help = nil ret end |
#help ⇒ Object
90 91 92 |
# File 'lib/haveapi/client/action.rb', line 90 def help @spec[:help] end |
#http_method ⇒ Object
103 104 105 |
# File 'lib/haveapi/client/action.rb', line 103 def http_method @spec[:method] end |
#input ⇒ Object
46 47 48 |
# File 'lib/haveapi/client/action.rb', line 46 def input @spec[:input] end |
#input_layout ⇒ Object
54 55 56 |
# File 'lib/haveapi/client/action.rb', line 54 def input_layout @spec[:input][:layout].to_sym end |
#input_params ⇒ Object
74 75 76 |
# File 'lib/haveapi/client/action.rb', line 74 def input_params @spec[:input][:parameters] end |
#name ⇒ Object
26 27 28 |
# File 'lib/haveapi/client/action.rb', line 26 def name @name end |
#namespace(src) ⇒ Object
66 67 68 |
# File 'lib/haveapi/client/action.rb', line 66 def namespace(src) @spec[src][:namespace] end |
#output ⇒ Object
50 51 52 |
# File 'lib/haveapi/client/action.rb', line 50 def output @spec[:output] end |
#output_layout ⇒ Object
58 59 60 |
# File 'lib/haveapi/client/action.rb', line 58 def output_layout @spec[:output][:layout].to_sym end |
#param_description(dir, name) ⇒ Object
82 83 84 |
# File 'lib/haveapi/client/action.rb', line 82 def param_description(dir, name) @spec[dir][:parameters][name] end |
#params ⇒ Object
78 79 80 |
# File 'lib/haveapi/client/action.rb', line 78 def params @spec[:output][:parameters] end |
#prepared_help ⇒ Object
99 100 101 |
# File 'lib/haveapi/client/action.rb', line 99 def prepared_help @prepared_help || @spec[:help] end |
#prepared_url ⇒ Object
Url with resolved parameters.
95 96 97 |
# File 'lib/haveapi/client/action.rb', line 95 def prepared_url @prepared_url || @spec[:url] end |
#provide_args(*args) ⇒ Object
111 112 113 |
# File 'lib/haveapi/client/action.rb', line 111 def provide_args(*args) apply_args(args) end |
#provide_url(url, help) ⇒ Object
115 116 117 118 |
# File 'lib/haveapi/client/action.rb', line 115 def provide_url(url, help) @prepared_url = url @prepared_help = help end |
#structure ⇒ Object
62 63 64 |
# File 'lib/haveapi/client/action.rb', line 62 def structure @spec[:output][:format] end |
#unresolved_args? ⇒ Boolean
107 108 109 |
# File 'lib/haveapi/client/action.rb', line 107 def unresolved_args? prepared_url =~ /:[a-zA-Z\-_]+/ end |
#update_description(spec) ⇒ Object
120 121 122 |
# File 'lib/haveapi/client/action.rb', line 120 def update_description(spec) @spec = spec end |
#url ⇒ Object
86 87 88 |
# File 'lib/haveapi/client/action.rb', line 86 def url @spec[:url] end |