apipie-rails 0.0.11 → 0.0.12

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 (41) hide show
  1. data/README.rdoc +8 -10
  2. data/app/controllers/apipie/apipies_controller.rb +12 -4
  3. data/app/views/apipie/apipies/_disqus.html.erb +11 -0
  4. data/app/views/apipie/apipies/apipie_404.html.erb +12 -0
  5. data/app/views/apipie/apipies/method.html.erb +1 -1
  6. data/app/views/apipie/apipies/resource.html.erb +1 -1
  7. data/app/views/layouts/apipie/apipie.html.erb +4 -15
  8. data/lib/apipie-rails.rb +1 -0
  9. data/lib/apipie/apipie_module.rb +10 -2
  10. data/lib/apipie/client/base.rb +131 -0
  11. data/lib/apipie/client/{template/cli_command.rb.tt → cli_command.rb} +21 -22
  12. data/lib/apipie/client/generator.rb +33 -30
  13. data/lib/apipie/client/{template/bin.rb.tt → main.rb} +13 -30
  14. data/lib/apipie/client/{template/rest_client_oauth.rb.tt → rest_client_oauth.rb} +1 -11
  15. data/lib/apipie/client/template/{client.gemspec.tt → a_name.gemspec.tt} +1 -0
  16. data/lib/apipie/client/template/bin/bin.rb.tt +30 -0
  17. data/lib/apipie/client/template/lib/a_name.rb.tt +27 -0
  18. data/lib/apipie/client/template/{cli.rb.tt → lib/a_name/commands/cli.rb.tt} +5 -8
  19. data/lib/apipie/client/template/lib/a_name/config.yml +6 -0
  20. data/lib/apipie/client/template/lib/a_name/resources/resource.rb.tt +22 -0
  21. data/lib/apipie/client/template/{version.rb.tt → lib/a_name/version.rb.tt} +0 -0
  22. data/lib/apipie/client/thor.rb +19 -0
  23. data/lib/apipie/dsl_definition.rb +3 -3
  24. data/lib/apipie/errors.rb +38 -0
  25. data/lib/apipie/helpers.rb +17 -0
  26. data/lib/apipie/param_description.rb +19 -10
  27. data/lib/apipie/resource_description.rb +2 -2
  28. data/lib/apipie/validator.rb +13 -33
  29. data/lib/apipie/version.rb +1 -1
  30. data/lib/tasks/apipie.rake +5 -0
  31. data/rubygem-apipie-rails.spec +80 -41
  32. data/spec/controllers/users_controller_spec.rb +20 -17
  33. data/spec/dummy/app/controllers/users_controller.rb +1 -0
  34. data/spec/dummy/app/views/layouts/application.html.erb +14 -7
  35. data/spec/dummy/config/initializers/apipie.rb +15 -0
  36. data/spec/lib/param_description_spec.rb +0 -0
  37. data/spec/lib/parameter_description_spec.rb +41 -0
  38. metadata +50 -40
  39. data/lib/apipie/client/template/base.rb.tt +0 -55
  40. data/lib/apipie/client/template/client.rb.tt +0 -13
  41. data/lib/apipie/client/template/resource.rb.tt +0 -19
@@ -1,55 +0,0 @@
1
- require 'rest_client'
2
- require 'oauth'
3
- require 'json'
4
- require '<%= name %><%= suffix %>/rest_client_oauth'
5
-
6
- module <%= class_base %><%= class_suffix %>
7
- class Base
8
- attr_reader :client
9
-
10
- def initialize(config = <%= class_base %><%= class_suffix %>.client_config, options = { })
11
- @client = RestClient::Resource.new config[:base_url],
12
- :user => config[:username],
13
- :password => config[:password],
14
- :oauth => config[:oauth],
15
- :headers => { :content_type => 'application/json',
16
- :accept => 'application/json' }
17
- end
18
-
19
- def call(method, path, options = { })
20
- payload, headers, params = options.values_at :payload, :headers, :params
21
- headers[:params] = params if params
22
-
23
- args = [method]
24
- args << payload.to_json if [:post, :put].include?(method)
25
- args << headers if headers
26
- process_data client[path].send(*args)
27
- end
28
-
29
- def validate_params!(options, valid_keys)
30
- return unless options.is_a?(Hash)
31
- invalid_keys = options.keys.map(&:to_s) - (valid_keys.is_a?(Hash) ? valid_keys.keys : valid_keys)
32
- raise ArgumentError, "Invalid keys: #{invalid_keys.join(", ")}" unless invalid_keys.empty?
33
-
34
- if valid_keys.is_a? Hash
35
- valid_keys.each do |key, keys|
36
- if options[key]
37
- validate_params!(options[key], keys)
38
- end
39
- end
40
- end
41
- end
42
-
43
- protected
44
-
45
- def process_data(response)
46
- data = begin
47
- JSON.parse(response.body)
48
- rescue JSON::ParserError
49
- response.body
50
- end
51
- return data, response
52
- end
53
-
54
- end
55
- end
@@ -1,13 +0,0 @@
1
- require '<%= name %><%= suffix %>/base'
2
- require '<%= name %><%= suffix %>/version'
3
-
4
- resource_files = Dir[File.expand_path('../<%= name %><%= suffix %>/resources/*.rb', __FILE__)]
5
- resource_files.each { |f| require f }
6
-
7
- module <%= class_base %><%= class_suffix %>
8
- def self.client_config
9
- @client_config ||= { :base_url => "http://localhost:3000",
10
- :oauth => { :consumer_key => 'consumer',
11
- :consumer_secret => 'shhhh' } }
12
- end
13
- end
@@ -1,19 +0,0 @@
1
- module <%= class_base %><%= class_suffix %>
2
- module Resources
3
- class <%= resource_name.camelize %> < <%= class_base %><%= class_suffix %>::Base
4
- <% resource[:methods].each do |method| -%>
5
-
6
- def <%= method[:name] %><%= "(#{ client_args(method).join(", ") })" if client_args(method).any? %>
7
- <% if method[:params].any? -%>
8
- validate_params!(params, <%= validation_hash(method).inspect.html_safe %>)
9
- <% end -%>
10
- <% http_method = api(method)[:http_method].downcase -%>
11
- call(:<%= http_method %>, "<%= substituted_url(method) %>"<%=
12
- (http_method == 'get' ? ", :params => params" : ", :payload => params") if method[:params].any?
13
- %>, :headers => headers)
14
- end
15
- <% end -%>
16
-
17
- end
18
- end
19
- end