oauth2-gen.go 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729
  1. // Package oauth2 provides access to the Google OAuth2 API.
  2. //
  3. // See https://developers.google.com/accounts/docs/OAuth2
  4. //
  5. // Usage example:
  6. //
  7. // import "google.golang.org/api/oauth2/v2"
  8. // ...
  9. // oauth2Service, err := oauth2.New(oauthHttpClient)
  10. package oauth2 // import "google.golang.org/api/oauth2/v2"
  11. import (
  12. "bytes"
  13. "encoding/json"
  14. "errors"
  15. "fmt"
  16. context "golang.org/x/net/context"
  17. ctxhttp "golang.org/x/net/context/ctxhttp"
  18. gensupport "google.golang.org/api/gensupport"
  19. googleapi "google.golang.org/api/googleapi"
  20. "io"
  21. "net/http"
  22. "net/url"
  23. "strconv"
  24. "strings"
  25. )
  26. // Always reference these packages, just in case the auto-generated code
  27. // below doesn't.
  28. var _ = bytes.NewBuffer
  29. var _ = strconv.Itoa
  30. var _ = fmt.Sprintf
  31. var _ = json.NewDecoder
  32. var _ = io.Copy
  33. var _ = url.Parse
  34. var _ = gensupport.MarshalJSON
  35. var _ = googleapi.Version
  36. var _ = errors.New
  37. var _ = strings.Replace
  38. var _ = context.Canceled
  39. var _ = ctxhttp.Do
  40. const apiId = "oauth2:v2"
  41. const apiName = "oauth2"
  42. const apiVersion = "v2"
  43. const basePath = "https://www.googleapis.com/"
  44. // OAuth2 scopes used by this API.
  45. const (
  46. // Know the list of people in your circles, your age range, and language
  47. PlusLoginScope = "https://www.googleapis.com/auth/plus.login"
  48. // Know who you are on Google
  49. PlusMeScope = "https://www.googleapis.com/auth/plus.me"
  50. // View your email address
  51. UserinfoEmailScope = "https://www.googleapis.com/auth/userinfo.email"
  52. // View your basic profile info
  53. UserinfoProfileScope = "https://www.googleapis.com/auth/userinfo.profile"
  54. )
  55. func New(client *http.Client) (*Service, error) {
  56. if client == nil {
  57. return nil, errors.New("client is nil")
  58. }
  59. s := &Service{client: client, BasePath: basePath}
  60. s.Userinfo = NewUserinfoService(s)
  61. return s, nil
  62. }
  63. type Service struct {
  64. client *http.Client
  65. BasePath string // API endpoint base URL
  66. UserAgent string // optional additional User-Agent fragment
  67. Userinfo *UserinfoService
  68. }
  69. func (s *Service) userAgent() string {
  70. if s.UserAgent == "" {
  71. return googleapi.UserAgent
  72. }
  73. return googleapi.UserAgent + " " + s.UserAgent
  74. }
  75. func NewUserinfoService(s *Service) *UserinfoService {
  76. rs := &UserinfoService{s: s}
  77. rs.V2 = NewUserinfoV2Service(s)
  78. return rs
  79. }
  80. type UserinfoService struct {
  81. s *Service
  82. V2 *UserinfoV2Service
  83. }
  84. func NewUserinfoV2Service(s *Service) *UserinfoV2Service {
  85. rs := &UserinfoV2Service{s: s}
  86. rs.Me = NewUserinfoV2MeService(s)
  87. return rs
  88. }
  89. type UserinfoV2Service struct {
  90. s *Service
  91. Me *UserinfoV2MeService
  92. }
  93. func NewUserinfoV2MeService(s *Service) *UserinfoV2MeService {
  94. rs := &UserinfoV2MeService{s: s}
  95. return rs
  96. }
  97. type UserinfoV2MeService struct {
  98. s *Service
  99. }
  100. type Jwk struct {
  101. Keys []*JwkKeys `json:"keys,omitempty"`
  102. // ServerResponse contains the HTTP response code and headers from the
  103. // server.
  104. googleapi.ServerResponse `json:"-"`
  105. // ForceSendFields is a list of field names (e.g. "Keys") to
  106. // unconditionally include in API requests. By default, fields with
  107. // empty values are omitted from API requests. However, any non-pointer,
  108. // non-interface field appearing in ForceSendFields will be sent to the
  109. // server regardless of whether the field is empty or not. This may be
  110. // used to include empty fields in Patch requests.
  111. ForceSendFields []string `json:"-"`
  112. }
  113. func (s *Jwk) MarshalJSON() ([]byte, error) {
  114. type noMethod Jwk
  115. raw := noMethod(*s)
  116. return gensupport.MarshalJSON(raw, s.ForceSendFields)
  117. }
  118. type JwkKeys struct {
  119. Alg string `json:"alg,omitempty"`
  120. E string `json:"e,omitempty"`
  121. Kid string `json:"kid,omitempty"`
  122. Kty string `json:"kty,omitempty"`
  123. N string `json:"n,omitempty"`
  124. Use string `json:"use,omitempty"`
  125. // ForceSendFields is a list of field names (e.g. "Alg") to
  126. // unconditionally include in API requests. By default, fields with
  127. // empty values are omitted from API requests. However, any non-pointer,
  128. // non-interface field appearing in ForceSendFields will be sent to the
  129. // server regardless of whether the field is empty or not. This may be
  130. // used to include empty fields in Patch requests.
  131. ForceSendFields []string `json:"-"`
  132. }
  133. func (s *JwkKeys) MarshalJSON() ([]byte, error) {
  134. type noMethod JwkKeys
  135. raw := noMethod(*s)
  136. return gensupport.MarshalJSON(raw, s.ForceSendFields)
  137. }
  138. type Tokeninfo struct {
  139. // AccessType: The access type granted with this token. It can be
  140. // offline or online.
  141. AccessType string `json:"access_type,omitempty"`
  142. // Audience: Who is the intended audience for this token. In general the
  143. // same as issued_to.
  144. Audience string `json:"audience,omitempty"`
  145. // Email: The email address of the user. Present only if the email scope
  146. // is present in the request.
  147. Email string `json:"email,omitempty"`
  148. // ExpiresIn: The expiry time of the token, as number of seconds left
  149. // until expiry.
  150. ExpiresIn int64 `json:"expires_in,omitempty"`
  151. // IssuedTo: To whom was the token issued to. In general the same as
  152. // audience.
  153. IssuedTo string `json:"issued_to,omitempty"`
  154. // Scope: The space separated list of scopes granted to this token.
  155. Scope string `json:"scope,omitempty"`
  156. // TokenHandle: The token handle associated with this token.
  157. TokenHandle string `json:"token_handle,omitempty"`
  158. // UserId: The obfuscated user id.
  159. UserId string `json:"user_id,omitempty"`
  160. // VerifiedEmail: Boolean flag which is true if the email address is
  161. // verified. Present only if the email scope is present in the request.
  162. VerifiedEmail bool `json:"verified_email,omitempty"`
  163. // ServerResponse contains the HTTP response code and headers from the
  164. // server.
  165. googleapi.ServerResponse `json:"-"`
  166. // ForceSendFields is a list of field names (e.g. "AccessType") to
  167. // unconditionally include in API requests. By default, fields with
  168. // empty values are omitted from API requests. However, any non-pointer,
  169. // non-interface field appearing in ForceSendFields will be sent to the
  170. // server regardless of whether the field is empty or not. This may be
  171. // used to include empty fields in Patch requests.
  172. ForceSendFields []string `json:"-"`
  173. }
  174. func (s *Tokeninfo) MarshalJSON() ([]byte, error) {
  175. type noMethod Tokeninfo
  176. raw := noMethod(*s)
  177. return gensupport.MarshalJSON(raw, s.ForceSendFields)
  178. }
  179. type Userinfoplus struct {
  180. // Email: The user's email address.
  181. Email string `json:"email,omitempty"`
  182. // FamilyName: The user's last name.
  183. FamilyName string `json:"family_name,omitempty"`
  184. // Gender: The user's gender.
  185. Gender string `json:"gender,omitempty"`
  186. // GivenName: The user's first name.
  187. GivenName string `json:"given_name,omitempty"`
  188. // Hd: The hosted domain e.g. example.com if the user is Google apps
  189. // user.
  190. Hd string `json:"hd,omitempty"`
  191. // Id: The obfuscated ID of the user.
  192. Id string `json:"id,omitempty"`
  193. // Link: URL of the profile page.
  194. Link string `json:"link,omitempty"`
  195. // Locale: The user's preferred locale.
  196. Locale string `json:"locale,omitempty"`
  197. // Name: The user's full name.
  198. Name string `json:"name,omitempty"`
  199. // Picture: URL of the user's picture image.
  200. Picture string `json:"picture,omitempty"`
  201. // VerifiedEmail: Boolean flag which is true if the email address is
  202. // verified. Always verified because we only return the user's primary
  203. // email address.
  204. //
  205. // Default: true
  206. VerifiedEmail *bool `json:"verified_email,omitempty"`
  207. // ServerResponse contains the HTTP response code and headers from the
  208. // server.
  209. googleapi.ServerResponse `json:"-"`
  210. // ForceSendFields is a list of field names (e.g. "Email") to
  211. // unconditionally include in API requests. By default, fields with
  212. // empty values are omitted from API requests. However, any non-pointer,
  213. // non-interface field appearing in ForceSendFields will be sent to the
  214. // server regardless of whether the field is empty or not. This may be
  215. // used to include empty fields in Patch requests.
  216. ForceSendFields []string `json:"-"`
  217. }
  218. func (s *Userinfoplus) MarshalJSON() ([]byte, error) {
  219. type noMethod Userinfoplus
  220. raw := noMethod(*s)
  221. return gensupport.MarshalJSON(raw, s.ForceSendFields)
  222. }
  223. // method id "oauth2.getCertForOpenIdConnect":
  224. type GetCertForOpenIdConnectCall struct {
  225. s *Service
  226. urlParams_ gensupport.URLParams
  227. ifNoneMatch_ string
  228. ctx_ context.Context
  229. }
  230. // GetCertForOpenIdConnect:
  231. func (s *Service) GetCertForOpenIdConnect() *GetCertForOpenIdConnectCall {
  232. c := &GetCertForOpenIdConnectCall{s: s, urlParams_: make(gensupport.URLParams)}
  233. return c
  234. }
  235. // Fields allows partial responses to be retrieved. See
  236. // https://developers.google.com/gdata/docs/2.0/basics#PartialResponse
  237. // for more information.
  238. func (c *GetCertForOpenIdConnectCall) Fields(s ...googleapi.Field) *GetCertForOpenIdConnectCall {
  239. c.urlParams_.Set("fields", googleapi.CombineFields(s))
  240. return c
  241. }
  242. // IfNoneMatch sets the optional parameter which makes the operation
  243. // fail if the object's ETag matches the given value. This is useful for
  244. // getting updates only after the object has changed since the last
  245. // request. Use googleapi.IsNotModified to check whether the response
  246. // error from Do is the result of In-None-Match.
  247. func (c *GetCertForOpenIdConnectCall) IfNoneMatch(entityTag string) *GetCertForOpenIdConnectCall {
  248. c.ifNoneMatch_ = entityTag
  249. return c
  250. }
  251. // Context sets the context to be used in this call's Do method. Any
  252. // pending HTTP request will be aborted if the provided context is
  253. // canceled.
  254. func (c *GetCertForOpenIdConnectCall) Context(ctx context.Context) *GetCertForOpenIdConnectCall {
  255. c.ctx_ = ctx
  256. return c
  257. }
  258. func (c *GetCertForOpenIdConnectCall) doRequest(alt string) (*http.Response, error) {
  259. var body io.Reader = nil
  260. c.urlParams_.Set("alt", alt)
  261. urls := googleapi.ResolveRelative(c.s.BasePath, "oauth2/v2/certs")
  262. urls += "?" + c.urlParams_.Encode()
  263. req, _ := http.NewRequest("GET", urls, body)
  264. googleapi.SetOpaque(req.URL)
  265. req.Header.Set("User-Agent", c.s.userAgent())
  266. if c.ifNoneMatch_ != "" {
  267. req.Header.Set("If-None-Match", c.ifNoneMatch_)
  268. }
  269. if c.ctx_ != nil {
  270. return ctxhttp.Do(c.ctx_, c.s.client, req)
  271. }
  272. return c.s.client.Do(req)
  273. }
  274. // Do executes the "oauth2.getCertForOpenIdConnect" call.
  275. // Exactly one of *Jwk or error will be non-nil. Any non-2xx status code
  276. // is an error. Response headers are in either
  277. // *Jwk.ServerResponse.Header or (if a response was returned at all) in
  278. // error.(*googleapi.Error).Header. Use googleapi.IsNotModified to check
  279. // whether the returned error was because http.StatusNotModified was
  280. // returned.
  281. func (c *GetCertForOpenIdConnectCall) Do(opts ...googleapi.CallOption) (*Jwk, error) {
  282. gensupport.SetOptions(c.urlParams_, opts...)
  283. res, err := c.doRequest("json")
  284. if res != nil && res.StatusCode == http.StatusNotModified {
  285. if res.Body != nil {
  286. res.Body.Close()
  287. }
  288. return nil, &googleapi.Error{
  289. Code: res.StatusCode,
  290. Header: res.Header,
  291. }
  292. }
  293. if err != nil {
  294. return nil, err
  295. }
  296. defer googleapi.CloseBody(res)
  297. if err := googleapi.CheckResponse(res); err != nil {
  298. return nil, err
  299. }
  300. ret := &Jwk{
  301. ServerResponse: googleapi.ServerResponse{
  302. Header: res.Header,
  303. HTTPStatusCode: res.StatusCode,
  304. },
  305. }
  306. if err := json.NewDecoder(res.Body).Decode(&ret); err != nil {
  307. return nil, err
  308. }
  309. return ret, nil
  310. // {
  311. // "httpMethod": "GET",
  312. // "id": "oauth2.getCertForOpenIdConnect",
  313. // "path": "oauth2/v2/certs",
  314. // "response": {
  315. // "$ref": "Jwk"
  316. // }
  317. // }
  318. }
  319. // method id "oauth2.tokeninfo":
  320. type TokeninfoCall struct {
  321. s *Service
  322. urlParams_ gensupport.URLParams
  323. ctx_ context.Context
  324. }
  325. // Tokeninfo:
  326. func (s *Service) Tokeninfo() *TokeninfoCall {
  327. c := &TokeninfoCall{s: s, urlParams_: make(gensupport.URLParams)}
  328. return c
  329. }
  330. // AccessToken sets the optional parameter "access_token":
  331. func (c *TokeninfoCall) AccessToken(accessToken string) *TokeninfoCall {
  332. c.urlParams_.Set("access_token", accessToken)
  333. return c
  334. }
  335. // IdToken sets the optional parameter "id_token":
  336. func (c *TokeninfoCall) IdToken(idToken string) *TokeninfoCall {
  337. c.urlParams_.Set("id_token", idToken)
  338. return c
  339. }
  340. // TokenHandle sets the optional parameter "token_handle":
  341. func (c *TokeninfoCall) TokenHandle(tokenHandle string) *TokeninfoCall {
  342. c.urlParams_.Set("token_handle", tokenHandle)
  343. return c
  344. }
  345. // Fields allows partial responses to be retrieved. See
  346. // https://developers.google.com/gdata/docs/2.0/basics#PartialResponse
  347. // for more information.
  348. func (c *TokeninfoCall) Fields(s ...googleapi.Field) *TokeninfoCall {
  349. c.urlParams_.Set("fields", googleapi.CombineFields(s))
  350. return c
  351. }
  352. // Context sets the context to be used in this call's Do method. Any
  353. // pending HTTP request will be aborted if the provided context is
  354. // canceled.
  355. func (c *TokeninfoCall) Context(ctx context.Context) *TokeninfoCall {
  356. c.ctx_ = ctx
  357. return c
  358. }
  359. func (c *TokeninfoCall) doRequest(alt string) (*http.Response, error) {
  360. var body io.Reader = nil
  361. c.urlParams_.Set("alt", alt)
  362. urls := googleapi.ResolveRelative(c.s.BasePath, "oauth2/v2/tokeninfo")
  363. urls += "?" + c.urlParams_.Encode()
  364. req, _ := http.NewRequest("POST", urls, body)
  365. googleapi.SetOpaque(req.URL)
  366. req.Header.Set("User-Agent", c.s.userAgent())
  367. if c.ctx_ != nil {
  368. return ctxhttp.Do(c.ctx_, c.s.client, req)
  369. }
  370. return c.s.client.Do(req)
  371. }
  372. // Do executes the "oauth2.tokeninfo" call.
  373. // Exactly one of *Tokeninfo or error will be non-nil. Any non-2xx
  374. // status code is an error. Response headers are in either
  375. // *Tokeninfo.ServerResponse.Header or (if a response was returned at
  376. // all) in error.(*googleapi.Error).Header. Use googleapi.IsNotModified
  377. // to check whether the returned error was because
  378. // http.StatusNotModified was returned.
  379. func (c *TokeninfoCall) Do(opts ...googleapi.CallOption) (*Tokeninfo, error) {
  380. gensupport.SetOptions(c.urlParams_, opts...)
  381. res, err := c.doRequest("json")
  382. if res != nil && res.StatusCode == http.StatusNotModified {
  383. if res.Body != nil {
  384. res.Body.Close()
  385. }
  386. return nil, &googleapi.Error{
  387. Code: res.StatusCode,
  388. Header: res.Header,
  389. }
  390. }
  391. if err != nil {
  392. return nil, err
  393. }
  394. defer googleapi.CloseBody(res)
  395. if err := googleapi.CheckResponse(res); err != nil {
  396. return nil, err
  397. }
  398. ret := &Tokeninfo{
  399. ServerResponse: googleapi.ServerResponse{
  400. Header: res.Header,
  401. HTTPStatusCode: res.StatusCode,
  402. },
  403. }
  404. if err := json.NewDecoder(res.Body).Decode(&ret); err != nil {
  405. return nil, err
  406. }
  407. return ret, nil
  408. // {
  409. // "httpMethod": "POST",
  410. // "id": "oauth2.tokeninfo",
  411. // "parameters": {
  412. // "access_token": {
  413. // "location": "query",
  414. // "type": "string"
  415. // },
  416. // "id_token": {
  417. // "location": "query",
  418. // "type": "string"
  419. // },
  420. // "token_handle": {
  421. // "location": "query",
  422. // "type": "string"
  423. // }
  424. // },
  425. // "path": "oauth2/v2/tokeninfo",
  426. // "response": {
  427. // "$ref": "Tokeninfo"
  428. // }
  429. // }
  430. }
  431. // method id "oauth2.userinfo.get":
  432. type UserinfoGetCall struct {
  433. s *Service
  434. urlParams_ gensupport.URLParams
  435. ifNoneMatch_ string
  436. ctx_ context.Context
  437. }
  438. // Get:
  439. func (r *UserinfoService) Get() *UserinfoGetCall {
  440. c := &UserinfoGetCall{s: r.s, urlParams_: make(gensupport.URLParams)}
  441. return c
  442. }
  443. // Fields allows partial responses to be retrieved. See
  444. // https://developers.google.com/gdata/docs/2.0/basics#PartialResponse
  445. // for more information.
  446. func (c *UserinfoGetCall) Fields(s ...googleapi.Field) *UserinfoGetCall {
  447. c.urlParams_.Set("fields", googleapi.CombineFields(s))
  448. return c
  449. }
  450. // IfNoneMatch sets the optional parameter which makes the operation
  451. // fail if the object's ETag matches the given value. This is useful for
  452. // getting updates only after the object has changed since the last
  453. // request. Use googleapi.IsNotModified to check whether the response
  454. // error from Do is the result of In-None-Match.
  455. func (c *UserinfoGetCall) IfNoneMatch(entityTag string) *UserinfoGetCall {
  456. c.ifNoneMatch_ = entityTag
  457. return c
  458. }
  459. // Context sets the context to be used in this call's Do method. Any
  460. // pending HTTP request will be aborted if the provided context is
  461. // canceled.
  462. func (c *UserinfoGetCall) Context(ctx context.Context) *UserinfoGetCall {
  463. c.ctx_ = ctx
  464. return c
  465. }
  466. func (c *UserinfoGetCall) doRequest(alt string) (*http.Response, error) {
  467. var body io.Reader = nil
  468. c.urlParams_.Set("alt", alt)
  469. urls := googleapi.ResolveRelative(c.s.BasePath, "oauth2/v2/userinfo")
  470. urls += "?" + c.urlParams_.Encode()
  471. req, _ := http.NewRequest("GET", urls, body)
  472. googleapi.SetOpaque(req.URL)
  473. req.Header.Set("User-Agent", c.s.userAgent())
  474. if c.ifNoneMatch_ != "" {
  475. req.Header.Set("If-None-Match", c.ifNoneMatch_)
  476. }
  477. if c.ctx_ != nil {
  478. return ctxhttp.Do(c.ctx_, c.s.client, req)
  479. }
  480. return c.s.client.Do(req)
  481. }
  482. // Do executes the "oauth2.userinfo.get" call.
  483. // Exactly one of *Userinfoplus or error will be non-nil. Any non-2xx
  484. // status code is an error. Response headers are in either
  485. // *Userinfoplus.ServerResponse.Header or (if a response was returned at
  486. // all) in error.(*googleapi.Error).Header. Use googleapi.IsNotModified
  487. // to check whether the returned error was because
  488. // http.StatusNotModified was returned.
  489. func (c *UserinfoGetCall) Do(opts ...googleapi.CallOption) (*Userinfoplus, error) {
  490. gensupport.SetOptions(c.urlParams_, opts...)
  491. res, err := c.doRequest("json")
  492. if res != nil && res.StatusCode == http.StatusNotModified {
  493. if res.Body != nil {
  494. res.Body.Close()
  495. }
  496. return nil, &googleapi.Error{
  497. Code: res.StatusCode,
  498. Header: res.Header,
  499. }
  500. }
  501. if err != nil {
  502. return nil, err
  503. }
  504. defer googleapi.CloseBody(res)
  505. if err := googleapi.CheckResponse(res); err != nil {
  506. return nil, err
  507. }
  508. ret := &Userinfoplus{
  509. ServerResponse: googleapi.ServerResponse{
  510. Header: res.Header,
  511. HTTPStatusCode: res.StatusCode,
  512. },
  513. }
  514. if err := json.NewDecoder(res.Body).Decode(&ret); err != nil {
  515. return nil, err
  516. }
  517. return ret, nil
  518. // {
  519. // "httpMethod": "GET",
  520. // "id": "oauth2.userinfo.get",
  521. // "path": "oauth2/v2/userinfo",
  522. // "response": {
  523. // "$ref": "Userinfoplus"
  524. // },
  525. // "scopes": [
  526. // "https://www.googleapis.com/auth/plus.login",
  527. // "https://www.googleapis.com/auth/plus.me",
  528. // "https://www.googleapis.com/auth/userinfo.email",
  529. // "https://www.googleapis.com/auth/userinfo.profile"
  530. // ]
  531. // }
  532. }
  533. // method id "oauth2.userinfo.v2.me.get":
  534. type UserinfoV2MeGetCall struct {
  535. s *Service
  536. urlParams_ gensupport.URLParams
  537. ifNoneMatch_ string
  538. ctx_ context.Context
  539. }
  540. // Get:
  541. func (r *UserinfoV2MeService) Get() *UserinfoV2MeGetCall {
  542. c := &UserinfoV2MeGetCall{s: r.s, urlParams_: make(gensupport.URLParams)}
  543. return c
  544. }
  545. // Fields allows partial responses to be retrieved. See
  546. // https://developers.google.com/gdata/docs/2.0/basics#PartialResponse
  547. // for more information.
  548. func (c *UserinfoV2MeGetCall) Fields(s ...googleapi.Field) *UserinfoV2MeGetCall {
  549. c.urlParams_.Set("fields", googleapi.CombineFields(s))
  550. return c
  551. }
  552. // IfNoneMatch sets the optional parameter which makes the operation
  553. // fail if the object's ETag matches the given value. This is useful for
  554. // getting updates only after the object has changed since the last
  555. // request. Use googleapi.IsNotModified to check whether the response
  556. // error from Do is the result of In-None-Match.
  557. func (c *UserinfoV2MeGetCall) IfNoneMatch(entityTag string) *UserinfoV2MeGetCall {
  558. c.ifNoneMatch_ = entityTag
  559. return c
  560. }
  561. // Context sets the context to be used in this call's Do method. Any
  562. // pending HTTP request will be aborted if the provided context is
  563. // canceled.
  564. func (c *UserinfoV2MeGetCall) Context(ctx context.Context) *UserinfoV2MeGetCall {
  565. c.ctx_ = ctx
  566. return c
  567. }
  568. func (c *UserinfoV2MeGetCall) doRequest(alt string) (*http.Response, error) {
  569. var body io.Reader = nil
  570. c.urlParams_.Set("alt", alt)
  571. urls := googleapi.ResolveRelative(c.s.BasePath, "userinfo/v2/me")
  572. urls += "?" + c.urlParams_.Encode()
  573. req, _ := http.NewRequest("GET", urls, body)
  574. googleapi.SetOpaque(req.URL)
  575. req.Header.Set("User-Agent", c.s.userAgent())
  576. if c.ifNoneMatch_ != "" {
  577. req.Header.Set("If-None-Match", c.ifNoneMatch_)
  578. }
  579. if c.ctx_ != nil {
  580. return ctxhttp.Do(c.ctx_, c.s.client, req)
  581. }
  582. return c.s.client.Do(req)
  583. }
  584. // Do executes the "oauth2.userinfo.v2.me.get" call.
  585. // Exactly one of *Userinfoplus or error will be non-nil. Any non-2xx
  586. // status code is an error. Response headers are in either
  587. // *Userinfoplus.ServerResponse.Header or (if a response was returned at
  588. // all) in error.(*googleapi.Error).Header. Use googleapi.IsNotModified
  589. // to check whether the returned error was because
  590. // http.StatusNotModified was returned.
  591. func (c *UserinfoV2MeGetCall) Do(opts ...googleapi.CallOption) (*Userinfoplus, error) {
  592. gensupport.SetOptions(c.urlParams_, opts...)
  593. res, err := c.doRequest("json")
  594. if res != nil && res.StatusCode == http.StatusNotModified {
  595. if res.Body != nil {
  596. res.Body.Close()
  597. }
  598. return nil, &googleapi.Error{
  599. Code: res.StatusCode,
  600. Header: res.Header,
  601. }
  602. }
  603. if err != nil {
  604. return nil, err
  605. }
  606. defer googleapi.CloseBody(res)
  607. if err := googleapi.CheckResponse(res); err != nil {
  608. return nil, err
  609. }
  610. ret := &Userinfoplus{
  611. ServerResponse: googleapi.ServerResponse{
  612. Header: res.Header,
  613. HTTPStatusCode: res.StatusCode,
  614. },
  615. }
  616. if err := json.NewDecoder(res.Body).Decode(&ret); err != nil {
  617. return nil, err
  618. }
  619. return ret, nil
  620. // {
  621. // "httpMethod": "GET",
  622. // "id": "oauth2.userinfo.v2.me.get",
  623. // "path": "userinfo/v2/me",
  624. // "response": {
  625. // "$ref": "Userinfoplus"
  626. // },
  627. // "scopes": [
  628. // "https://www.googleapis.com/auth/plus.login",
  629. // "https://www.googleapis.com/auth/plus.me",
  630. // "https://www.googleapis.com/auth/userinfo.email",
  631. // "https://www.googleapis.com/auth/userinfo.profile"
  632. // ]
  633. // }
  634. }