Class: HaveAPI::Client::Action

Inherits:
Object
  • Object
show all
Defined in:
lib/haveapi/client/action.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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_pathObject

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

Returns:

  • (Boolean)


30
31
32
# File 'lib/haveapi/client/action.rb', line 30

def auth?
  @spec[:auth]
end

#descriptionObject



42
43
44
# File 'lib/haveapi/client/action.rb', line 42

def description
  @spec[:description]
end

#examplesObject



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

#helpObject



90
91
92
# File 'lib/haveapi/client/action.rb', line 90

def help
  @spec[:help]
end

#http_methodObject



103
104
105
# File 'lib/haveapi/client/action.rb', line 103

def http_method
  @spec[:method]
end

#inputObject



46
47
48
# File 'lib/haveapi/client/action.rb', line 46

def input
  @spec[:input]
end

#input_layoutObject



54
55
56
# File 'lib/haveapi/client/action.rb', line 54

def input_layout
  @spec[:input][:layout].to_sym
end

#input_paramsObject



74
75
76
# File 'lib/haveapi/client/action.rb', line 74

def input_params
  @spec[:input][:parameters]
end

#nameObject



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

#outputObject



50
51
52
# File 'lib/haveapi/client/action.rb', line 50

def output
  @spec[:output]
end

#output_layoutObject



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

#paramsObject



78
79
80
# File 'lib/haveapi/client/action.rb', line 78

def params
  @spec[:output][:parameters]
end

#prepared_helpObject



99
100
101
# File 'lib/haveapi/client/action.rb', line 99

def prepared_help
  @prepared_help || @spec[:help]
end

#prepared_urlObject

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

#structureObject



62
63
64
# File 'lib/haveapi/client/action.rb', line 62

def structure
  @spec[:output][:format]
end

#unresolved_args?Boolean

Returns:

  • (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

#urlObject



86
87
88
# File 'lib/haveapi/client/action.rb', line 86

def url
  @spec[:url]
end