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.



6
7
8
9
10
11
12
# File 'lib/haveapi/client/action.rb', line 6

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.



4
5
6
# File 'lib/haveapi/client/action.rb', line 4

def resource_path
  @resource_path
end

Instance Method Details

#aliases(include_name = false) ⇒ Object



29
30
31
32
33
34
35
# File 'lib/haveapi/client/action.rb', line 29

def aliases(include_name = false)
  if include_name
    [@name] + @spec[:aliases]
  else
    @spec[:aliases]
  end
end

#auth?Boolean

Returns:

  • (Boolean)


25
26
27
# File 'lib/haveapi/client/action.rb', line 25

def auth?
  @spec[:auth]
end

#descriptionObject



37
38
39
# File 'lib/haveapi/client/action.rb', line 37

def description
  @spec[:description]
end

#examplesObject



65
66
67
# File 'lib/haveapi/client/action.rb', line 65

def examples
  @spec[:examples]
end

#execute(*args) ⇒ Object



14
15
16
17
18
19
# File 'lib/haveapi/client/action.rb', line 14

def execute(*args)
  ret = @api.call(self, *args)
  @prepared_url = nil
  @prepared_help = nil
  ret
end

#helpObject



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

def help
  @spec[:help]
end

#http_methodObject



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

def http_method
  @spec[:method]
end

#inputObject



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

def input
  @spec[:input]
end

#input_layoutObject



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

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

#input_paramsObject



69
70
71
# File 'lib/haveapi/client/action.rb', line 69

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

#nameObject



21
22
23
# File 'lib/haveapi/client/action.rb', line 21

def name
  @name
end

#namespace(src) ⇒ Object



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

def namespace(src)
  @spec[src][:namespace]
end

#outputObject



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

def output
  @spec[:output]
end

#output_layoutObject



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

def output_layout
  @spec[:output][:layout].to_sym
end

#param_description(dir, name) ⇒ Object



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

def param_description(dir, name)
  @spec[dir][:parameters][name]
end

#paramsObject



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

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

#prepared_helpObject



94
95
96
# File 'lib/haveapi/client/action.rb', line 94

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

#prepared_urlObject

Url with resolved parameters.



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

def prepared_url
  @prepared_url || @spec[:url]
end

#provide_args(*args) ⇒ Object



106
107
108
# File 'lib/haveapi/client/action.rb', line 106

def provide_args(*args)
  apply_args(args)
end

#provide_url(url, help) ⇒ Object



110
111
112
113
# File 'lib/haveapi/client/action.rb', line 110

def provide_url(url, help)
  @prepared_url = url
  @prepared_help = help
end

#structureObject



57
58
59
# File 'lib/haveapi/client/action.rb', line 57

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

#unresolved_args?Boolean

Returns:

  • (Boolean)


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

def unresolved_args?
  prepared_url =~ /:[a-zA-Z\-_]+/
end

#update_description(spec) ⇒ Object



115
116
117
# File 'lib/haveapi/client/action.rb', line 115

def update_description(spec)
  @spec = spec
end

#urlObject



81
82
83
# File 'lib/haveapi/client/action.rb', line 81

def url
  @spec[:url]
end