qiita 1.0.3 → 1.0.4

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: c4211a3b9680b3b19ebdfdff075232a5c593daf4
4
- data.tar.gz: a17deb8975e4705cac7a7e11733d0123dd242d6f
3
+ metadata.gz: 0f6eca33e49eb4d3e65ade2c99c3660212fd1d94
4
+ data.tar.gz: a01378d0df082e39e694fa2e485f4050ca7ac2e4
5
5
  SHA512:
6
- metadata.gz: 24408f2e390576142dcf777bf9fae6db4d70607ad6449be92f3d6d22ba4b630fd1b925e2b23742390bdefd06adff96311da357ffe487bab0dd1d710044ce3786
7
- data.tar.gz: c1775d021c901c07c54c89941e536cdffb1442b6a8c053a1bd69eccd779cf8ec56a40d5cd6799c208ab1f0cb0a7b86a6a0d178526dfa4b5cd74a714026728874
6
+ metadata.gz: 861e2f18dffa7617c16b70517dd0dc9c132f93abb4622f5d0855ef8201e6eeeb233642a1ba0400d7877c0b576a13f291a702e43800ffe0dbb35b4621ed57a7f3
7
+ data.tar.gz: ce4024eec88826e162ec5eb5030aac264e8174fddb2418244a6e6d383084d2b0d529f71216e85a7a41588efbc63f1d0fd6137b8289f09cbc183a421731117374
data/CHANGELOG.md CHANGED
@@ -1,3 +1,6 @@
1
+ ## 1.0.4
2
+ * Add list_teams method
3
+
1
4
  ## 1.0.3
2
5
  * Escape request URL path
3
6
 
@@ -210,6 +210,13 @@ module Qiita
210
210
  get("/api/v2/users/#{user_id}/following_tags", params, headers)
211
211
  end
212
212
 
213
+ # ### Qiita::Client#list_teams(params = nil, headers = nil)
214
+ # 現在のリクエストで認証されているユーザが所属している全てのチームを返します。
215
+ #
216
+ def list_teams(params = nil, headers = nil)
217
+ get("/api/v2/teams", params, headers)
218
+ end
219
+
213
220
  # ### Qiita::Client#list_templates(params = nil, headers = nil)
214
221
  # 全てのテンプレート一覧を返します。
215
222
  #
data/lib/qiita/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Qiita
2
- VERSION = "1.0.3"
2
+ VERSION = "1.0.4"
3
3
  end
@@ -0,0 +1,152 @@
1
+ #!/usr/bin/env ruby
2
+ # # script/generate-objc
3
+ # Generates a subclass of AFHTTPSessionManager from given JSON Schema.
4
+ #
5
+ # ## Usage
6
+ # Run this script with a path to JSON Schema of Qiita API v2, available only for staff.
7
+ #
8
+ # ```sh
9
+ # bundle exec ./script/generate-objc [-h|-m] INCQiitaSessionManager /path/to/json/schema > INCQiitaSessionManager.[h|m]
10
+ # ```
11
+ #
12
+ require "active_support/core_ext/object/try"
13
+ require "active_support/core_ext/string/indent"
14
+ require "active_support/core_ext/string/inflections"
15
+ require "active_support/core_ext/string/strip"
16
+ require "json_schema"
17
+ require "optparse"
18
+ require "ostruct"
19
+ require "yaml"
20
+
21
+ # View object class to generate String representation of each method.
22
+ method_class = Class.new(OpenStruct) do
23
+ def to_s
24
+ if header?
25
+ <<-EOS.strip_heredoc
26
+ /// #{description}
27
+ #{return_type_marker}#{wrapped_method_signature(return_type_marker.length).indent(8).strip};
28
+ EOS
29
+ else
30
+ <<-EOS.strip_heredoc
31
+ #{return_type_marker}#{wrapped_method_signature(return_type_marker.length).indent(8).strip} {
32
+ NSString *path = [NSString stringWithFormat:#{path_format_and_arguments}];
33
+ return [self #{request_method}:path parameters:parameters success:success failure:failure];
34
+ }
35
+ EOS
36
+ end
37
+ end
38
+
39
+ private
40
+
41
+ def return_type_marker
42
+ "- (NSURLSessionDataTask *)"
43
+ end
44
+
45
+ def wrapped_method_signature(offset)
46
+ components = method_signature.split(/ (?=[0-9A-Za-z_]+:)/)
47
+ colon_position = offset + components[0].index(":")
48
+ aligned = [components[0]]
49
+ components[1..-1].each do |component|
50
+ aligned << " " * (colon_position - component.index(":")) + component
51
+ end
52
+ aligned.join("\n")
53
+ end
54
+
55
+ def method_signature
56
+ camelize_objcish(method_name) + with_arguments
57
+ end
58
+
59
+ def with_arguments
60
+ arguments = required_argument_names.map {|name|
61
+ camelize_objcish(name) + ":(NSString *)" + camelize_objcish(name)
62
+ }
63
+ arguments << "parameters:(NSDictionary *)parameters"
64
+ arguments << "success:(void (^)(NSURLSessionDataTask *task, id responseObject))success"
65
+ arguments << "failure:(void (^)(NSURLSessionDataTask *task, NSError *error))failure"
66
+ "With" + upcase_first(arguments.join(" "))
67
+ end
68
+
69
+ def camelize_objcish(name)
70
+ name = name.split(/_/).map {|component|
71
+ case component
72
+ when "id" then "i_d" # to camelize into "ID"
73
+ else component
74
+ end
75
+ }.join("_")
76
+ name =~ /^i_d/ ? name.camelize : name.camelize(:lower)
77
+ end
78
+
79
+ def upcase_first(s)
80
+ s[0].upcase + s[1..-1]
81
+ end
82
+
83
+ def path_format_and_arguments
84
+ placeholder_pattern = %r<{\(.*/([^/]+)\)}>
85
+ format = %Q<@"#{href.gsub(placeholder_pattern, '%@')}">
86
+ keys = href.scan(placeholder_pattern).flatten
87
+ arguments = keys.map {|key| camelize_objcish(key) }
88
+ ([format] + arguments).join(", ")
89
+ end
90
+
91
+ def path
92
+ ?" + href.gsub(%r<{\(.*/([^/]+)\)}>, '#{\1}') + ?"
93
+ end
94
+
95
+ def header?
96
+ _generates_header
97
+ end
98
+ end
99
+
100
+ opt = OptionParser.new
101
+ opt.on("-h CLASS") {|c| $class_name = c; $generates_header = true }
102
+ opt.on("-m CLASS") {|c| $class_name = c; $generates_header = false }
103
+ opt.parse!(ARGV)
104
+ unless $class_name
105
+ abort "Neither -h nor -m given. Aborted."
106
+ end
107
+ path_to_json_schema = ARGV[0]
108
+ hash = YAML.load_file(path_to_json_schema)
109
+ schema = JsonSchema.parse!(hash).tap(&:expand_references!)
110
+ links = schema.properties.values.map(&:links).flatten
111
+ methods = links.map do |link|
112
+ method_class.new(
113
+ _generates_header: $generates_header,
114
+ available_parameters: (link.schema.try(:properties) || {}).map do |name, property|
115
+ {
116
+ description: property.description,
117
+ name: name,
118
+ type: property.type,
119
+ }
120
+ end,
121
+ description: link.description,
122
+ href: link.href,
123
+ method_name: link.title,
124
+ request_method: link.method.upcase,
125
+ required_argument_names: link.href.scan(%r<{\(.*/([^/]+)\)}>).flatten,
126
+ )
127
+ end
128
+ if $generates_header
129
+ puts <<-EOS.strip_heredoc
130
+ #import <AFNetworking/AFHTTPSessionManager.h>
131
+
132
+ @interface #{$class_name} : AFHTTPSessionManager
133
+
134
+ #{methods.join("\n").indent(4).strip}
135
+
136
+ @end
137
+ EOS
138
+ else
139
+ puts <<-EOS.strip_heredoc
140
+ #import "#{$class_name}.h"
141
+
142
+ @implementation #{$class_name}
143
+
144
+ + (instancetype)manager {
145
+ return [[[self class] alloc] initWithBaseURL:[NSURL URLWithString:@"https://qiita.com"]];
146
+ }
147
+
148
+ #{methods.join("\n").indent(4).strip}
149
+
150
+ @end
151
+ EOS
152
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: qiita
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.3
4
+ version: 1.0.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ryo Nakamura
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-10-22 00:00:00.000000000 Z
11
+ date: 2014-12-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -225,6 +225,7 @@ files:
225
225
  - lib/qiita/version.rb
226
226
  - qiita.gemspec
227
227
  - script/generate
228
+ - script/generate-objc
228
229
  - spec/qiita/client_spec.rb
229
230
  - spec/spec_helper.rb
230
231
  homepage: https://github.com/increments/qiita-rb